SAS Studio Workshop – Proc Content
SAS Studio Overview :
First , we create a new folder to store SAS datasets . We click on “Server Files and Folders ” tab on left viewing pane of SAS window as :
We click on Files(Home) to open files stored in it . We right click on Files tab and click on New and then click on Folder to create a new folder .
It will open the following pane as :
We give the name of folder and click on Save button to save the folder .
We can upload files by right click on learn folder and click on Upload Files as:
It will open following pane :
We can click on Choose Files button to choose SAS dataset to upload . It open following open pane :
We can choose SAS dataset and click on Open button . It will upload dataset in learn folder. You can see we upload lots of SAS dataset in learn folder.
We right click on lean folder and click on Create tab and then click on Library to create a new library to store SAS dataset .
It will open given pane :
We create a new library “LEARN” . We give the name of library and click on OK button to create it. We can checked the Re-create option to recreate the library whenever we start our SAS studio . We can see LEARN library in Libraries tab under My Libraries as :
We can use any of SAS files under LEARN library to work onwards .
The CONTENTS procedure
The CONTENT procedure allows us to create a SAS output that describes either the contents of a SAS library or the descriptor information of a SAS data set . In order to view the contents of a SAS library , we use following code :
PROC CONTENTS data = libref._ALL_ NODS;
libref – it is the library name .
_ALL_ – option requests a listing of all the SAS files in the library .
NODS – it stands for “no details” , it is used to suppress the printing of detailed information about each file when you specify the _ALL_ option .
We want to explore contents of baseball dataset . We used following code :
proc contents data=learn.baseball ;
It shows the number of observations in the dataset . Here , the baseball dataset contains 322 observations.
The number of variables in the dataset . Here , baseball dataset contains 22 variables.
The date and time that the dataset was created and last modified.
It shows the dataset’s variables and their attributes .
# – The original order of the variable in the columns of the dataset
Type – Whether the variable is numeric or character
Len – It represents length of the variable
Format – The assigned format of the variable
Informat – The format of the variable when it was read into SAS
Label – The label associated with variable . If variables do not have labels, this column will be identical to the variable name .
It shows alphabetic list of variables and attributes .
We can use directory option to see all the dataset in learn library .
proc contents data=learn.sales directory;
It shows Directory where datasets stored :
It shows all the dataset in learn library :
It shows contents of sales dataset :
We use following statements:
data = learn._all_ represents all datasets in learn library .
nods – option suppress the printing of detailed information about each dataset in learn library .
It shows only list of datasets in learn library :
proc contents data= learn._all_ nods;
We check out the attributes of dataset and variables .
proc contents data=learn.sales ;
We used nodetails option on sales dataset . It shows same output of alphabetic list of variables and attributes .
proc contents data=learn.sales nodetails;
We use short option to see alphabetic list of variable names .
The following code shows the alphabetic list of variable names of sales dataset :
proc contents data=learn.sales short;
We used varnum option to see variables in creation order with attributes .
proc contents data=learn.sales varnum ;
We used combination of two options varnum and short . It shows variable names of sales dataset in creation order .
proc contents data=learn.sales varnum short;
We used position option to see both alphabetic and creation order list of variables and attributes .
proc contents data=learn.sales position;
We used two options position and short . It will show variables names in alphabetic and creation order .
proc contents data=learn.sales position short;
We use short option to show the alphabetic list of variables names of all datasets in learn library .
proc contents data=learn._all_ short;
We use varnum option to see list of variables in creation order of all datasets in learn library .
proc contents data=learn._all_ varnum;
It shows the list of datasets in learn library :
It shows the contents of all the datasets :
We used varnum and short options to see list of variables in creation order of all datasets in learn library.
proc contents data=learn._all_ varnum short;
We can see all the datasets in learn library with nods option .
proc contents data=learn._all_ nods;
* export the variable names and their position number into a data set called “data_info”;
We used following options as :
noprint – to not print output in results window .
out = data_info tells SAS to save output in data_info dataset .
keep = name varnum tells SAS to keep only name and varnum variables in data_info dataset .
proc contents data = sashelp.class noprint out = data_info (keep = name varnum);