May 26, 2021 SAS
Programming SAS first requires creating/reading the dataset to memory and then analyzing the data. W e need to understand the process in which one of the programs is written to achieve this goal.
The following illustration shows the steps to write to create an SAS program in the given order.
Each SAS program must have all these steps to complete reading input data, analyzing data, and giving analytical output. I n addition, the RUN statement at the end of each step needs to complete the execution of the step.
This step involves loading the desired dataset into SAS memory and identifying the variables (also known as columns) of the dataset. I t also captures records (also known as observations or principals). T he syntax of the DATA statement is as follows.
DATA data_set_name; #Name the data set. INPUT var1,var2,var3; #Define the variables in this data set. NEW_VAR; #Create new variables. LABEL; #Assign labels to variables. DATALINES; #Enter the data. RUN;
The following example shows the simple case of naming a dataset, defining variables, creating new variables, and entering data. H ere the string variable ends with a $, and the numeric value does not have it.
DATA TEMP; INPUT ID $ NAME $ SALARY DEPARTMENT $; comm = SALARY*0.25; LABEL ID = 'Employee ID' comm = 'COMMISION'; DATALINES; 1 Rick 623.3 IT 2 Dan 515.2 Operations 3 Michelle 611 IT 4 Ryan 729 HR 5 Gary 843.25 Finance 6 Nina 578 IT 7 Simon 632.8 Operations 8 Guru 722.5 Finance ; RUN;
This step includes calling the SAS built-in program to analyze the data.
PROC procedure_name options; #The name of the proc. RUN;
The following example shows the average of the numeric variables in the data set printed using the MEANS procedure.
PROC MEANS; RUN;
You can use conditional output statements to display data in a data set.
PROC PRINT DATA = data_set; OPTIONS; RUN;
The following example shows that only a few records are generated from the data set in the output using the where clause.
PROC PRINT DATA=TEMP; WHERE SALARY > 700; RUN;
Here is the full code for each of these steps.
The output of the above code is visible in the RESULTS tab.