









































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
How to use the WHERE statement in PROC steps in SAS to read a subset of data and the importance of sorting data using PROC SORT. It includes examples and instructions on how to sort data in ascending and descending orders, print data with PROC PRINT, and write custom reports using DATA steps.
Typology: Summaries
1 / 49
This page cannot be seen from the preview
Don't miss anything!










































Math 3210 Dr. Zeng Department of Mathematics California State University, Bakersfield
DATA Artists;
INFILE '/home/bzeng/my_content/Artists.dat'; INPUT Name $ 1-21 Genre $ 23-40 Origin $ 42;
RUN;
PROC PRINT DATA = Artists;
WHERE Genre = 'Impressionism'; TITLE 'Major Impressionist Painters'; FOOTNOTE 'F = France N = Netherlands U = US';
RUN;
PROC SORT DATA= messy OUT= neat NODUPKEY DUPOUT=extraobs;
from lowest to highest.
keyword DESCENDING to the BY statement before each variable that should be sorted in reverse order.
to sort first by State (from A-Z) and then City (from Z to A) within State: BY State DESCENDING city;
DATA marine;
INFILE '/home/bzeng/my_content/Lengths.dat'; INPUT Name $ Family $ Length @@;
RUN;
PROC SORT DATA = marine OUT = seasort
NODUPKEY;
BY Family DESCENDING Length;
PROC PRINT DATA = seasort;
TITLE 'Whales and Sharks';
RUN;
numeric and character variables.
observation for the whale shark.
PROC SORT SORTSEQ=LINGUISTIC (STRENGTH=PRIMARY);
unsorted order ASCII
Linguistic Sort (strength=primaray) ella ANNA amanda amanda Zoe ANNA Zoe amanda ella ANNA ella Zoe
unsorted order ASCII
Linguistic Sort (NUMERIC_COLLATION=ON) 1500m freestyle 100m backstroke 50m freestyle
200m breaststroke 1500m freestyle 100m backstroke
100m backstroke 200m breaststroke 200m breaststroke 50mm freestyle 50m freestyle 1500m freestyle
DATA addresses; INFILE '/home/bzeng/my_content/Mail.dat'; INPUT Name $6. Street $18. City $9. State $6.; RUN;
PROC SORT DATA = addresses OUT = sortone SORTSEQ = LINGUISTIC (NUMERIC_COLLATION = ON); BY Street; PROC PRINT DATA = sortone; TITLE 'Addresses Sorted by Street'; RUN;
PROC SORT DATA = addresses OUT = sorttwo SORTSEQ = LINGUISTIC (STRENGTH = PRIMARY); BY State; PROC PRINT DATA = sorttwo; TITLE 'Addresses Sorted by State'; RUN;
Practice: what will the result be without using these options?
Printing Your Data with PROC PRINT
By default, SAS prints the observation numbers along with
the variables’ values. If you don’t want observation
numbers, use the NOOBS option in the PROC PRINT
statement.
For example,
PROC PRINT DATA= data-set NOOBS;
The following are optional statements that sometimes
come in handy:
Students from two fourth-grade classes are selling candy to
earn money for a special field trip. The class earning more
money gets a free box of candy. The following are the data
for the results of the candy sale. The students’ names are
followed by their classroom number, the data they turned
in their money, the type of candy: mint patties or chocolate
dinosaurs, and the number of boxes sold. The teachers
want a report giving the money earned for each classroom,
the money earned by each student, the type of candy sold,
and the date the students returned their money.
DATA sales;
INFILE '/home/bzeng/my_content/CandySales.dat'; INPUT Name $ 1-11 Class @15 DateReturned MMDDYY10. CandyType $ Quantity;
Profit = Quantity * 1.25;
PROC SORT DATA = sales;
BY Class;
PROC PRINT DATA = sales;
BY Class; SUM Profit; VAR Name DateReturned CandyType Profit; TITLE 'Candy Sales for Field Trip by Class';
RUN;