Working with SAS frequently involves use of:
SAS libraries are locations for your SAS data sets. Just as you can store files in multiple locations on a hard drive, you can also store data in multiple libraries within SAS.
Typically, however, you work with only two libraries: the work library and a library you specify.
This code below will create a library called mylib, which is the libref. The libname statement points to a SAS-Data folder on the C:\ drive. Note that pointing to physical locations on your machine is not supported in SAS OnDemand.
libname mylib 'C:\SAS-Data';
There are rules to SAS librefs, the most important of which is that they are limited to 8 characters. See this SAS doc for more information.
This youtube video shows you how to make a permanent library in SAS OnDemand.
This is where you write your SAS program.
Let’s export some data from a built-in R data set and then import it into SAS.
head(morley) #shows the first few rows of the morley dataset
## Expt Run Speed
## 001 1 1 850
## 002 1 2 740
## 003 1 3 900
## 004 1 4 1070
## 005 1 5 930
## 006 1 6 850
write.csv(morley, 'C:/Users/T530/Desktop/morley.csv')
#writes the morley data set to my desktop
A few notes on what I did before importing:
/* Generated Code (IMPORT) */
/* Source File: morley.csv */
/* Source Path: /home/rileymy0/sasuser.v94 */
/* Code generated on: 12/23/18, 2:18 PM */
%web_drop_table(WORK.IMPORT);
FILENAME REFFILE '/home/rileymy0/sasuser.v94/morley.csv';
PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=WORK.IMPORT;
GETNAMES=YES;
RUN;
proc contents data=work.import; run;
%web_open_table(WORK.IMPORT);
The code can be described as follows:
The code above demonstrates the following features of the SAS language:
SAS has two methods of commenting:
*This is one example of a comment;
/* This is another example of a comment */
proc contents data=work.import; run; /*this type is better for in-line*/
/* because this comment type doesn't have a semi-colon */
In the import above, the log displayed the following:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 PROC CONTENTS DATA=WORK.IMPORT; RUN;
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.04 seconds
user cpu time 0.04 seconds
system cpu time 0.00 seconds
memory 2388.78k
OS Memory 32176.00k
Timestamp 12/24/2018 04:09:20 PM
Step Count 31 Switch Count 0
Page Faults 0
Page Reclaims 481
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 16
72
73 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
85
The log is useful to check on the progress of a SAS program execution:
The SAS log is the only place to find information relevant to debugging errors in your program.
This displays any output from your SAS program. For example, the PROC CONTENTS output above was displayed in the results window.
Let’s print the morley data in SAS, which will also display in the Results window.
PROC PRINT DATA=WORK.IMPORT; RUN;
Click here for the PROC PRINT output.