A Quick Code Into to SAS

A simple code example SAS server

Iftekher Mamun
3 min readSep 7, 2019
Starting SAS Machine on a Server

After you have finished installing SAS and have the machine running, let’s follow some basic code on how to program in SAS and what it looks like.

We will follow a simple flight gate departure dataset. First we will create the dataset with the following:

data departures;

Then we will increase the limit of character count to a certain number:

input USGate $15.;

Then we will insert the actual data into the dataset with this:

datalines;

That is telling SAS that we are going to import information regarding the dataset, which are these:

San Francisco
Honolulu
New York
; /* this signifies the end of the statement, rather input for dataline*/
run;

Finally, we run the dataset with this:

proc print;
run;

Lets run those and look at the log and the result output:

The log shows if it ran properly or not
This is our output table from the dataset

Now lets create a new dataset:

data aircode;

And now input information from the first dataset with set:

set departures;

Then we increase the character count a bit more, just in case as we are going to input more information:

length airport $20.;

Finally, we will add more data, but now more like an if else statement function. This way, SAS can incorporate the dataset from earlier and push it through the function we are about to run:

if USGate = 'San Francisco' then Airport = 'SFO'; 
else if USGate = 'Honolulu' then Airport = 'HNL';
else if USGate = 'New York' then Airport = 'JFK or LGA';
run;

Finally, lets run and look at the log and output again:

proc print;
run;
First the log, showing no error again
Notice that this table has an extra column with additional information.

And that is it. SAS is relatively simple to use and you can see the similarity between other programming language. I am familiar with MySQL and Python so it was relatively easy for me to figure out SAS. Thanks for reading.

--

--