SAS is a data based system. It is not much use if you can’t get data into it. In the following exercises, I will show you how to import common data files.
You can download some practice data files here: examplefiles
This is a zip file. Unzip the folder and copy the contents (three files) into a place of your choosing. Now open up SAS Studio:
Select MyFolders on the left pain and select the upload files icon
Now select Choose Files
Your files should now be located under My Folders
Import Txt
If you double click on mileage.txt in the left panel, a preview of the data will pop up.
Now to import this information into SAS, we use the following code.
DATA mileage;
INFILE '/folders/myfolders/mileage.txt';
INPUT year miles;
RUN;
DATA – names your data set
INFILE choose data source
INPUT – names variables(columns)
Now click the Run icon
Now check your results, you data is loaded.
A quick note, SAS chooses a single space as the default delimiter. If your file has a different delimiter like comma.
SAS is a dominant force in the world of analytics. While some may argue it is on its way out, a quick query of current Data Scientist job listing in the NYC area shows many companies are still looking for SAS experience.
Luckily for us, SAS has a free University Edition that we can work with to learn SAS for free.
You can Google SAS University Edition or follow the link below:
First you will need to download and install VirtualBox, you can download it from the SAS page. They have a link.
Next download the SAS OVA package
Once downloaded, just double click on the OVA file and it should automatically install itself into VirtualBox. Note – you must have VirtualBox installed first.
Now, before we can start, you have to make a shared folder on our computer. I just created the following in on my PC. C:\SasUniversity\Myfolders
Now start VirtualBox: Go to SAS University Edition
Right click and click Settings
Now select Shared Folders – click the blue folder with the green plus sign on the right
Type in the path of your folder, the name of your folder and check Auto-mount and Make Permanent
Close the Setting window out and double click on SAS University Edition to get it started.
Once it fully loads, you will get a screen like this
Type the path given into a browser on your machine.
Here is SAS Studio. The Left panel of the screen manages folders and other admin tasks. The right panel is where we type our code. We are going to start with a very simple task of creating a small data set of car names, # of cylinders, and # of doors.
Here is the code, I will explain below the picture.
Now to breakdown the code (note the ; (semicolon) at the end of each line)
DATA cars; -- this names our data set
INPUT NAME$ CYLINDERS DOORS; -- names our variables (or columns if you
will) note the $ after NAME - this
indicates NAME is
a string
datalines; -- the data to input into our set will follow below
you may see some people use CARDS; in place of
datalines I believe this dates back to earlier
versions where one told how much memory to associate
to each row. Now they are interchangeable.
Miata 4 2
Sonata 4 4
Corvette 8 2
Mustang 8 2
Civic 4 2
Accord 4 4
Elentra 4 4
; -- end of datalines
RUN; -- run command - like the go in SQL
Now click the Run icon above your code
And view the output – we have created a data set – congrats!!