The SAS system if capable of reading in data in many different forms. This post will focus on the importation of data in CSV format. The CSV format is very common in both business and academia and can be created with Excel. The data that will be imported for the purposes of this post will be the monthly civilian unemployment rate which will be obtained from the St. Louis Federal Reserve Bank’s research database (http://research.stlouisfed.org/fred2/series/UNRATE?cid=12)
Explanation of Code:
The code above creates a temporary data set called “fed”. It first goes into my “k” drive by using the “infile” command to retrieve the CSV file that contains the data. The ” DLM = ‘,’ ” option tells SAS that the delimiter is a comma. The “DSD” option makes the program ignore data values enclosed in quotes, does not read quotes as part of the data value, and it treats two delimiters in a row as missing values. Next, an informant is used to tell SAS that the field “date” is saved in mmddyyyy format and the field needs to hold 10 characters. Then the program tells SAS that the variable names in this data set are called “date” and “value”.
Once the commands to input the data are read by the program it would be nice to get an output of the data. This is what the “proc print” command going to do for us once we specify what data set is going to be printed. Next, the “title” command is used to give the output a nice title while the “format” command is used to ensure the data is printed in the standard format of mmddyyyyy.
The log does not show any errors. There were a total of 764 observations read into the file which does correspond to the number of months in the period 01/01/1948 to 07/07/2011 excluding the deader. The number of variables is two as expected with the date being on field and the unemployment rate being the other field.
Explanation of Output:
The SAS output window shows that the data was imported correctly. The data does start on the second line. Short of deleting the title in the Excel file, there is probably a way or making the SAS program ignore the title when reading in the data. The next post will consist of manipulating this data with various functions and logical statements.