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;
Code -
proc print data=sasuser.admit;sum fee;run;
3. To get the sum total for more than one specified columns
Code -
proc print data=sasuser.admit;sum fee height;run;
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;
5. Selecting variables for printing without default obs column
Code -
proc print data=sasuser.admit noobs;var age sex height fee;sum fee ;run;
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;
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;
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;
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;
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;
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;
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;
0 Comments
If you have any doubt please comment or write us to - admin@datahark.com