PROC PRINT in SAS - What Does the PRINT Procedure Do

The Proc PRINT prints the observations in a SAS data set using all or some of the variables, It's a reporting procedure, you can create some dynamic reports with the help of proc print, that could include groups the data and calculates totals and subtotals for numeric variables.

Here are some Examples for Proc print -


1. First Proc print to get the output for sasuser.admit dataset in output window


Code -

proc print data=sasuser.admit;
run;
Proc Print Output

2. To get the sum total for a specified column, you can use the sum keyword


Code -

proc print data=sasuser.admit;
sum fee;
run;
Proc Print Sum


3. To get the sum total for more than one specified columns


Code -

proc print data=sasuser.admit;
sum fee height;
run;
Proc print sum of two variables


4. Selecting variables for printing, the use of the var keyword


Code -

proc print data=sasuser.admit;
var age sex height fee;
sum fee ;
run;
Var keyword in proc


5. Selecting variables for printing  without default obs column


Code -

proc print data=sasuser.admit noobs;
var age sex height fee;
sum fee ;
run;
Noobs in Proc Print


6. Use of no obs - It gives the total no of observations and shows the obs column too


Code -

proc print data=sasuser.admit no obs;
var age sex height fee;
sum fee ;
run;

/* same can be achieved by N; 

proc print data=sasuser.admit N;
var age sex height fee;
sum fee ;
run;
use of no obs or N in proc print


7. Use of ID statement - The id statement basically replaces the obs column with the specified variable against the id keyword


Code -

proc print data=admit;
var age sex height fee;
id name;
sum fee ;
run;
use of ID statement in proc print


8. More than one variable in ID statement  - If you specify two variables in the id statement then those two vars replace the obs columns and proc print of data is also displayed.


Code - 

proc print data=sasuser.admit;
id name age height;
run;
more than one variable in ID


9. The use of where statement is to filter the observations (Note - we can’t use IF statement in proc print to filter data)


Code -

proc print data=admit;
var age sex height fee;
where age gt 30;
sum fee ;
run;
where condition in proc print


10. The use of '?' operator along with where condition for filtering the data


Code - 

proc print data=sasuser.admit;
var age sex height fee name;
where name ? 'er';
sum fee ;
run;
use of ? operator in Where statement


11. The use of double spacing in the listing output between the rows


Code - 

proc print data=sasuser.admit double;
var age sex height fee name;
where name ? 'er';
sum fee ;
run;
Double spacing in proc print


12. Titles in Proc print -  The use of title in the listing output, title or title1 is the same


Code - 

title1 'Proc Print Examples';
title3 'Please subscribe datahark on Facebook, youtube and visit our website';
title4 'website - https://www.datahark.com/'
title5 'facebook - https://www.facebook.com/datahark/'
title6 'youtube - https://www.youtube.com/channel/UCZAPTZ0YvrTiKdh2WgnxEBA or Search for Datahark'

proc print data=sasuser.admit;
var age sex height fee name;
where name ? 'er';
sum fee ;
run;
Titles in proc print














Post a Comment

0 Comments