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…

call macro present in another SAS code

Today, I will discuss about How to call macro whose code is present in another SAS script. First, we need to understand why another SAS script is required. Answer to this is very simple that is redundant code. Many a times, particular portion of code is used in many SAS scripts like getting today’s date or yesterday’s date or yesterday’s month or year. For this , It is recommended to write a separate code and call that code in the existing script.Here, I have created two SAS Scripts. FIRST SCRIPT…

equivalent of sum of columns in SAS

Today, I will discuss about “How to design SAS code which is equivalent of sum of columns in database. Consider the below employee details. In order to get sum of Year-2019 and Year-2020, we need to use add (+) operator to achieve the same. See the below Query and data for the same. Here, i applied ,normal addition, sum using ISNULL function, difference using absolute(ABS) function. In order to achieve the same in SAS . Create the same Datasets . See the below Screen Shot for the same. Now, create…

features of SAS Tool

Today, I will discuss about the features of SAS. As I started my career as database developer ,hence I will share features which is similar to database commands which will help you all in migration projects. 1. Connect to any data base like Sql-server , Netezza, Oracle using connect to odbc command.2. Perform nesting of SAS scripts inside one SAS script using macro and include commands.3. Perform union all, all joins(left outer,right outer,full outer) operations in SAS using merge and set commands4. Read data from any file like csv ,pipe(|)…

equivalent of union all in SAS

Today , I will discuss about ” How to code in SAS which is equivalent of union all in Database.See the below Data set in Sql Server. See the output of union all in Sql Server Perform the same Steps for SAS as well. First, create the same data set in SAS. Below code will perform union all logic in SAS.* Tricky part here is renaming of columns , otherwise data will not look alike that of sql server. See the SAS output for the same.

equivalent of full outer join in SAS

Today, I will discuss about “How to design SAS code which is equivalent of full outer join in database”. We created the two datasets in sql-server. when we apply full outer join on above data set. In SAS, create the dataset same as TEST1 and TEST2 tables.* Always remember to sort the data. Make a habit of this in SAS. Merge the above datasets using the below code. See the final output for the same.

equivalent of inner join in SAS

Today, I will discuss about “How to design code in SAS which is equivalent to inner join in database where column name are different in both the data sets or tables in terms of database.Below is the data in two tables. Now, apply inner Join in both the tables on condition COL1=COL4 and below is the output of the same. Next step , try to first create the same dataset in SAS and then apply logic on that data to get result equivalent of inner join.Create the dataset same as…