IF AND THEN STATEMENT IN SAS

In this post, I will discuss about the “If and then Statements in SAS”. Here , I have created the dataset where I have mentioned emp_id in numbers as well as single character. See the below SS related to Dataset created.Now, on the above dataset I will apply If and then statement and assign numbers to single character emp_id. See the below code for the same. DATA EMP_NEW_DET;SET EMP_DET;IF EMP_ID=”A” THEN EMP_ID= “1”;ELSE IF EMP_ID=”B” THEN EMP_ID= “2”;RUN; Once you execute the above code, the below output will appear.

SUM USING GROUP BY IN SAS

In this post, I will discuss about “How to perform sum function based on particular column in SAS”. In one of my blog , I have already explained about Sorting in SAS using Employee Data. Once sorting is done based on the Emp_id, I will sum the salary the based on the emp_id. Below is the code for the same. DATA EMP_SUM_DET(drop=SALARY);SET EMP_DET;BY EMP_ID;if First.EMP_ID then TotalSalary=0;TotalSalary+SALARY;if Last.EMP_ID;run;Here, we are using If, first and last function . For each employee, we are setting the intial TotalSalary=0 . Here , another…

SORT DATA IN SAS

In this post, I will discuss How to sort data in SAS. Sorting plays a very important role in SAS. With and without sorting, data changes drastically in SAS. Consider the below data lines in SAS. DATA EMP_DET; INPUT EMP_ID SALARY; DATALINES; 1 10000 2 10500 3 12000 1 13000 2 12300 3 15000 ; run; When the above code executes, the output will be as below.As it is clearly seen, data is neither sorted by salary nor by emp_id. In order to sort the data, “proc sort” syntax is…