UNC-Wilmington Department of Economics and Finance ECN 377 Dr. Chris Dumas SAS--Proc Print and Proc Sort Proc Print Proc Print is used to print data to the Output Screen in SAS. Proc Print does not print data to a printer!! Suppose you have a dataset in SAS named dataset01. You can tell SAS to print the dataset to the SAS Output Window using the following commands: proc print data=dataset01; run; Suppose you want to print dataset02 instead of dataset01, then use: proc print data=dataset02; run; Suppose you want to print only rows 7 to 20 in dataset01, then use: proc print data=dataset01 (firstobs=7 obs=20); run; Note: You must include the parentheses. Notice that “firstobs” specifies the row number of the first row you want to print. Notice that “obs” specifies the row number of the last row you want to print. Suppose you want to print only those rows where variable Z is equal to 2, then use the “where” command inside proc print: proc print data=dataset01; where Z=2; run; Suppose you want to print only variables X, TIME and GDP in dataset01, then use: proc print data=dataset01; var X TIME GDP; run; The “var” command inside the proc print procedure tells SAS to print only the list of variables that follows the command word “var”. 1 Proc Sort Proc Sort allows you to sort the rows in a dataset. This can be important because some SAS procedures require that the rows be sorted in a particular way before the procedure is used. Suppose you have a dataset in SAS named dataset01. You can tell SAS to sort the dataset rows according to the values of variable Y using the following commands: proc sort data=dataset01; by Y; run; If variable Y is a numeric variable, SAS will sort the data rows so that the row with the smallest value of Y is at the top and the row with the largest value of Y is at the bottom. If variable Y is a character/text variable, SAS will sort the data rows in alphabetical order according to the vales of Y. So, the rows with values of Y that begin with “a” will be at the top of the list, and rows with values of Y that begin with “z” will be at the bottom of the list. If you want the sort the rows in reverse order, you can use the “descending” option in front of the sort variable. For example, the following commands sort the data according to descending values of variable Y (from largest to smallest, if Y is a numeric variable, or from “z” to “a”, if Y is a character/text variable): proc sort data=dataset01; by descending Y; run; Sorting by more than one variable. Suppose you have data on several customers (variable name CUSTOMER), and for each customer you have data on daily purchases of three different product types (variable PRODTYPE), and the month in which each purchase occurred (variable MONTH). Suppose you want to sort your data by customer, and then by month for each customer, and then by product type (this would put all the sales for a given customer together). You could use the following commands: proc sort data=dataset01; by CUSTOMER MONTH PRODTYPE; run; Suppose instead that you wanted to sort by product type, then by month, and then by customer (this would put all the sales of a given product type together): proc sort data=dataset01; by PRODTYPE MONTH CUSTOMER; run; 2