Your First Program
Prerequisites: Getting Set Up
Open a new program in SAS Studio and type:
data _null_;
put 'Hello, world!';
put 'Welcome to SAS.';
run;
Press F3. The RESULTS tab stays empty — PUT writes to the
log. Open the LOG tab; below the echoed lines of your program
you'll see:
Hello, world!
Welcome to SAS.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
data _null_;starts a DATA step that doesn't create a data set — handy for calculations and messages.putwrites text (or values) to the log.run;ends the step and runs it.- Every statement ends with a semicolon. Forgetting one is the most common SAS mistake.
- SAS keywords and names are not case-sensitive:
DATA,data, andDataare the same. Text inside quotes is kept exactly as written.
(Timing lines like the ones above appear after every step; later examples leave them out and are marked "log (abridged)".)
Your first data set and report
data pets;
input name $ species $ age;
datalines;
Rex dog 4
Tom cat 7
Nemo fish 1
;
run;
proc print data=pets;
run;
Output:
Obs name species age
1 Rex dog 4
2 Tom cat 7
3 Nemo fish 1
- The DATA step creates a data set called
petswith three variables (columns) and three observations (rows). inputnames the variables; the$afternameandspeciesmakes them character variables.ageis numeric.datalines;starts the data, and a line containing only;ends it.proc printdisplays the data set.Obsis the observation number.
Practice
Create a data set books with a title (one word) and a number of pages
for three books, and print it.
Show solution
data books;
input title $ pages;
datalines;
Dune 412
Emma 474
Ulysses 730
;
run;
proc print data=books;
run;
Obs title pages
1 Dune 412
2 Emma 474
3 Ulysses 730