BASE SAS Programming – Working with CSV Files – DSD Option




Hello people. Welcome to another post in the “BASE SAS Tutorial” series. We are making some quick progress in the last few posts. So far we have discussed how SAS reads text files as list inputs in the form of delimited files ( space delimited, or otherwise). In this post, we will look more closely at the a very useful option that is used with the infile statement. This is the DSD option.

Let us quickly first lay down the uses of the DSD option before we see its practical application.

  1. It can change any default delimiter from the space to a comma. This can be useful because very often the data files are received in the .csv format. So instead of using the DLM option, we can simply use the DSD as it also provides other benefits.
  2. If there are two consecutive delimiters, it considers the same as a missing value. The data doesn’t need to have specified missing values. This is very useful as we can imagine, how often we get data files where there are missing values. The DSD option helps to resolve this problem quite easily.
  3. Lastly, any double quotes around the character fields are stripped.

These are very useful capabilities for only three words.

Let us consider the data as shown below:

Please note the the missing value on the third record and the double quote qualifiers for the Gender column. See below the sample SAS Program to import the above sample data using the DSD option.

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

See below the results as they appear in the log and the output folder:

Log Tab:

Output Data Tab:

Play around with the DSD option and see how it responds to changes in the raw data file with each import. Please remember to review the log after running every sample script even if the results are all good. Any good SAS programmer must be in the habit of being able to read the SAS log. It is quite important.

You can 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.