- Back to Home »
- Learning , PROC PRINT , SAS »
- Learning SAS: Tweaking PROC PRINT to display the data
Posted by : Netbloggy
Saturday, September 19, 2015
PROC PRINT in SAS has a lot of options which can help us tweak the way we display our data.
Options like n = caption of summary, firstobs = no. of first observations & obs = last observation to be processed.
Problem 1:
List the first 6 observations in data set Blood. Include only the variables Subject,
WBC (white blood cell), RBC (red blood cell), and Chol. Label the last three
variables “White Blood Cells,” “Red Blood Cells,” and “Cholesterol,” respectively.
Omit the Obs column, and place Subject in the first column. Be sure the column
headings are the variable labels, not the variable names.
Solution:
proc print data=A15001.A01_Blood (obs=6) n = 'No. of Observations = ' label; /* printing only 6 obs */ label WBC = 'White Blood Cells' RBC = 'Red Blood Cells' Chol = 'Cholesterol'; ID Subject; /* omit obs & place the id variable at first */ var WBC RBC Chol; run;
Output:
Learning:
- Different options of PROC PRINT
Problem 2:
List the four observations from data set Blood (3-6). Also group the output report by
BloodType.
Solution:
/* sorting before using grouping in PROC PRINT */ proc sort data=A15001.A01_Blood; by BloodType; run; proc print data=A15001.A01_Blood (firstobs=3 obs=6) /* printing only 4 obs */ n = 'No. of Observations = '; by BloodType; ID Subject; /* omit obs & place the id variable at first */ var WBC RBC Chol; run;
Output:
Learning:
- Using BY to group the output in PROC PRINT
- Using FirstObs to select a start point while displaying the output