Basic SAS Procedures Greg Jenkins
1
Overview • SAS procedures are functions that generally take data in either from a data set, or specified options, and then output some information. • That’s pretty vague, but we will look at some basic SAS procedures for examples. • Coding and options are similar for most procedures. 2
Syntax Common to Most Procedures • Most procedures have the following general syntax: proc something
; <where conditional statements;> 3
Syntax Common to Most Procedures • The “data=“ statement specifies the data set the procedure will use, if the procedure requires an input data set(some don’t). If the “data=“ statement is left out the last data set created is used. • “Where” clause allows subsetting of data. • “by” statement allows the processing of the procedure separately for each level of the “by” variable, you need to sort the input data set by the “by” variable. 4
Syntax Common to Most Procedures • The “label” and “format” statements work exactly the same as in the data step. The formats and labels are removed from the data set after the procedure is ended. • Some procedures are interactive and start processing when the proc statement is submitted. Others require a “run;” statement at the end of the procedure code to start processing, or start processing by reaching the beginning of another SAS statement.
5
Syntax Common to Most Procedures • Most procedures will end on their own after all the procedure code is submitted, but for “interactive” procedures, such as: proc gplot, gchart, sql, reg, and some others; a “quit;” statement must be used to end the procedure unless code related to another procedure, data step, SAS option, etc. is reached. 6
Types of Procedures • There are lots of them, but we’ll just discuss a few groups, and few procedures within those groups. • First, we’ll look at base SAS procedures. • The first procedures we’ll talk about are report writing related: print, printto, tabulate, and report. 7
Proc Print • Used to output the contents of a SAS dataset. • Basic syntax: proc print ; run; 8
Proc Print • “label” statement tells SAS whether you want the labels or variable names of variables used as column headers. • The “var” statement lets you list the variables in the data set you want printed. • By default observations(rows) in the dataset are identified by the row number, the “id” statement allows you change this to a set of variables(don’t include these variables in the “var” statement unless you want them printed out twice ). 9
Other Report Writing Procedures • proc printto allows output, and log files to be redirected to a specified text file. • Proc report & tabulate are “fancier” versions of proc print, they can also do some minor calculations.
10
Basic Statistics Procedures • The next group of basic procedures we’ll talk about are procedures that do basic statistics, like simple frequency (contingency) tables, univariate statistics, etc. • These procedures are: proc univariate, means, freq, rank, and corr. 11
Proc Univariate • Calculates basic statistics for one variable, mean, median, etc., also does tests. proc univariate ; 12
Proc Univariate • If no variables are specified in the “var” option the procedure will run on all the variables in the data set specified. • This procedure outputs a wide variety of statistics and can also create output datasets containing these statistics. • Proc univariate will conduct t-tests, and tests for non-normality(if the normal option is used). • It will also produce histograms, probability plots, … 13
Proc Means • Basically a scaled down version of proc univariate, does not conduct tests, fewer statistics, etc. • Its advantage over proc univariate is that it processes quicker, and is easier to work with if the aim is to get an output data set that contains statistics of more than one variable. proc univariate does not do this. 14
Proc Freq • Basically creates frequency, and contingency tables. proc freq ; 15
Proc Freq • In the table statement if you want to create a contingency table of one or more variables join the variables by an asterisk(*). proc freq; table gender*smoke; run; 16
Proc Freq • Proc freq will do testing, approximate, and exact. • Outputs measures of association, agreement, and odds ratios. • Also has several output data sets.
17
Other Basic Statistics Procedures • Proc rank, will output a data set of ranks based on variables from an input dataset and various options. • Proc corr, outputs correlation type information, for comparisons of two continuous variables, also does nonparametric comparisons. 18
Utility Procedures • These procedures are utilities, they are for the most part work with data sets, they: sort, edit, copy, etc. They do not generally produce output. • Some of the procedures we have already seen are: proc format, proc import(using the import wizard), proc sql(we’ll talk about later), and proc contents. 19
Brief Overview: Utility Procedures • Proc copy – copies SAS datasets, catalogs. • Proc datasets – works on datasets in a library. • Proc compare – compares two datasets. • Proc append – concatenates data sets. • Proc transpose – transposes data(we’ll talk about this later) 20
Categories of Other Procedures • SAS/STAT – statistical procedures, learn about these for the most part in a statistics classes. • SAS/ACCESS – procedures for importing data from other sources. • SAS/OR – procedures related to operations research(proc netwflow for network problems, etc.) 21
Categories of Other Procedures • SAS/ETS – statistical procedures, time series tools • SAS/FSP – data entry tools • SAS/GIS – tools for GIS(Geographic Information Systems) data • SAS/GRAPH – graphics • SAS/IML – Interactive matrix language 22
Categories of Other Procedures • SAS/EIS – data warehousing tools • SAS/QC – quality control procedures, like proc capability(nice procedure for normalprobability plots, etc.) • And many, many more …
23
Output from Procedures • Output for SAS procedures are generally sent to the output window(interactive SAS) or .lst file(Line Mode SAS), however some procedures have no output or send the output to the log window, or .log file, • A relatively new improvement to SAS is ODS(Output Delivery System), improves the way output is delivered from procedures. • ODS still doesn’t deliver “great” output but it can be useful, as well, it can create .pdf, .html, .rtf, and many other file types. 24
“GUI’s” for Procedures • As mentioned earlier there are some graphical user interfaces for procedures, one that is very useful is the SAS/SQL GUI. • The SQL GUI can be found be selecting “tools” then “Query”. • Another GUI is for proc import, this is the import data wizard that you’ve seen. • SAS/ASSIST is a GUI for some other procedures. 25
Help on Syntax of Procedures • If you get stuck and forget the syntax of a procedure look it up in the “online” help. • A keyboard short cut to find help on a procedure is to put the cursor on the procedure “word”(i.e. proc freq, proc contents, etc.) in the editor window and hit F1 and it will bring up the syntax for the procedure(thanks to Dr. Pereira for this tip!) 26
Help on the Help! • It’s a long running joke(although not a good one!) that you need a SAS manual to read a SAS manual. • There’s a good description of SAS’s syntax convention in the SAS OnlineDoc Version 8, which I didn’t copy because of copyright reasons! 27
Related Documents