SAS Basics
Share
The SAS programs , data files and the results of the programs are saved using various extensions in windows .
The following file extensions are –
*.sas – It represents the SAS code file which can be edited using SAS editor or text editor.
*.log – It represents the SAS Log file . It contains information such as errors, warnings etc.
*.sas7bdat – it represents SAS data file which contains a SAS data set including variable names , labels and observation.
Important SAS Keyboard Shortcuts
Description Shortcut key
Run or submit a program F3 or F8
Comment the selected code Ctrl + /
Stop Processing or cancel submitted program Ctrl+ Break
Convert selected text to upper case Ctrl + Shift + U
Find text Ctrl + F
Find and replace text Ctrl + H
Copy selection Ctrl + C
Paste Ctrl + V
Cut selection Ctrl + X
Go to a particular line Ctrl + G
Move to beginning of line Home
Move to top Ctrl + Home
Move to end Ctrl + End
To close the active window Ctrl + F4
To exit the SAS System Alt + F4
Open a new program window F4
Libraries
Permanent library
We can create permanent library by following steps –
First click on leftmost button under Libraries .
It will open following window of New Library –
We give name satya to new library . We click on checkbox to re-create library every time when we open SAS Studio.
We click on Browse , then it will open this window –
Then , click on OK button to create library .
We can see SATYA library under My Libraries tab as –
We can also create permanent library by using libname statement in SAS 9.2 window version.
libname satya “C:\Users\dell\Desktop”;
We create a new dataset apple and store in satya library.
Data satya.apple;
You can see library SATYA store APPLE dataset .
We do not store anything in our dataset . So , it shows this window –
Temporary library
We create a dataset to store it temporarily as –
Data abc;
/*OR*/
Data work.abc;
The dataset stores in Work library . As you can see ABC dataset under Work library in below window –
Data step
The structure of Data step is as-
Data dataset_name;
Input variable_names;
Datalines/Cards;
Data <- We enter data to store in dataset
; <- It shows end of data
Run;
Data – It is used to create a dataset with dataset_name as name of the dataset .
Input – It shows the list of variable names.
Datalines/Cards – It is used to read data internally. We used Cards in previous version of SAS.
Data – it shows the data to store in the dataset.
Run – To execute the program .
SAS variable types
It has two types –
Numeric variable
This is the default variable type . It store only digits from 0 to 9 .
Syntax –
INPUT VAR1 VAR2 VAR3;
We create three variables VAR1 , VAR2 , VAR3 .
We can create id ,salary and age variables as –
Input id salary age ;
Character Variable
It store data which includes string, digits and special symbols like marine , abc12 , #dfg89 etc.
Syntax –
INPUT VAR1 $ VAR2 $ ;
We create two character variables VAR1 , VAR2.
We create character variables name , gender as –
Input name $ gender $;
We create a new dataset “new” . It stores name and marks of students .SAS reads line-by-line to store data in dataset .It reads data column-wise separated by space.
Data new;
input name$ marks;
datalines;
Satya 45
Ram 78
;
run;
We can execute our SAS code by using F3 function key .
It shows output of program in OUTPUT DATA window –
We create a dataset “abc” . It includes id , name and salary .
data abc;
input id name$ salary ;
datalines;
101 Dan 45000
102 Derry 8564
103 Henry 87562
;
run;
We can execute our SAS code by using F3 function key .
The output of SAS code can be seen in OUTPUT DATA window –
The dataset ABC store in WORK library .