Ekta Aggarwal
PROC PRINT in SAS
To view the already existing datasets we have PROC PRINT in SAS. We shall learn
In this tutorial we will make use of SAS' inbuilt dataset: sashelp.baseball
By default PROC PRINT displays all of the rows in the dataset. To view the first N rows we define:
OPTIONS OBS = 20;
PROC PRINT DATA = sashelp.BASEBALL;
RUN;
WHERE Statement
We can also view a subset of the dataset using WHERE statement.
Task: Print only those rows where Team is Cleveland.
PROC PRINT DATA = sashelp.BASEBALL(WHERE = (Team = 'Cleveland'));
RUN;
KEEP Statement
For large datasets we also have the liberty to print only specific columns using KEEP statement:
PROC PRINT DATA = sashelp.BASEBALL(WHERE = (Team = 'Cleveland') KEEP = Team Name);
RUN;
DROP Statement
We can also drop some columns using DROP statement.
Warning: Do not use DROP and KEEP together.
PROC PRINT DATA = sashelp.BASEBALL(WHERE = (Team = 'Cleveland') DROP = Name NHITS);
RUN;
RENAME Statement
We can also rename the columns as follows:
PROC PRINT DATA = sashelp.BASEBALL( RENAME = Team = TEAMNAME);
RUN;
Adding a TITLE
We can also provide a title to our print output using TITLE statement as follows:
PROC PRINT DATA = sashelp.BASEBALL(WHERE = (Team = 'Cleveland') KEEP = Team Name);
TITLE 'Cleveland players';
RUN;