BASE SAS Programming – Using DLM and DSD Options Together




Hi fellow data analysts. We are having a lot of fun putting together these posts for “BASE SAS Tutorial” series. We certainly hope you are enjoying and learning something from them as well. We have covered some very important ground so far but we have a long way to go. In this post, we will be discussing a possible scenario where are demonstrate the use of the DLM and DSD option together.

We have seen features of the DSD option. It is important to note that they all work independent of each other. For instance, if we were to set the delimiter as “/” using the DLM option, an accompanying DSD option would still identify missing values between consecutive delimiters without resetting the default delimiter to comma. Let us look at the sample data we would be using for this demo.

Sample Data

The below provided sample SAS program is used to read in the above sample data.

data sample1;
infile ‘/folders/myshortcuts/myFolder/Sample data – CSV.txt’ dsd dlm = “/”;
input gender $ Age Height Weight;
run;

Note: We are using the DSD and DLM options simultaneously in order to read in data from a delimited file with the delimiter “/”. The DSD option is useful to identify the missing values in the data. The outputs generated from this code are:

Logs:

Output:

As can be seen in the above screenshots, the data is read in appropriately. This combination is used so often in a day to day scenario that it is a must to learn, understand and deploy as if it were your second nature. Often, folks get confused, but with practice it is fairly easy to use and implement. Keep practicing by creating other sample data sets and see how the codes responds to changes.

Please find relevant reference books in the sidebar of this post, if you should want to purchase the same for further studying. BASE SAS Certification guide and the Little SAS book are extremely useful for preparation and also act as a wonderful reference for SAS concepts.

Please sign up for our newsletter, so that we may keep you posted on the latest activity on our website and Youtube channel.



BASE SAS Programming – Import Delimited Files




Hello all. Nice to have you going strong with our “BASE SAS Tutorial’ series. In the previous post, we looked at how the SAS tool reads text files with space delimiter. Spaces being the default delimiter for the tool. However, in the real world scenario, data is never provided from any source with space as the delimiter value. Luckily, SAS allows a great deal of flexibility to read delimited files with a variety of options of different elements. Let us look at the sample program below where we try to import the same data as in the previous post, but with the “/” character as the delimiter instead of the the default space.

Data sample1;
infile ‘/folders/myshortcuts/myFolder/Sample data – delimiter.txt’ dlm = “/”;
input gender $ Age Height Weight;
run;

Snapshot of the data contained in the file;

The output of the code as it would appear in the log and the output tab:

Log:

Output Tab:

This is the most common method of importing data into any SAS tool that is available for end users. It is important to understand clearly how the simple code shared in this post is working so that it can be scaled for data files with more number of columns and complications. Please try it out and share your experience in the comments below. Please find relevant reference books in the sidebar, if you should want to purchase the same for further studying. Please sign up for our newsletter, so that we may keep you posted on the latest activity on our website and Youtube channel.