Você está na página 1de 2

data uspresidents; Chapter 1:Base Programming

input president $ party $ number; -Rules for SAS variables:


datalines; Variable names should be 32 characters or fewer
adams f 2 lincoln r 16 grant r 18 kennedy d 35 ; Variable names must start with a letter or underscore ( _ )
data iris; Variable names cannot contain special characters (e.g. ! @ # $ % ^ & etc.)
infile 'c:\users\palapali\desktop\iris.txt' firstobs=2; -The numeric/character variable has a default length of 8.
input species sepal_len sepal_wid petal_len petal_wid; -A SAS data set has the following naming convention:
proc print data=uspresidents; DATA libref.membername;
title 'in-stream data'; The libref must be other than WORK for a SAS data set to be permanent. A two-level name makes the data set permanent; a one-level name
proc tabulate data=iris; makes the data set temporary. One level data set gets assigned to Work, which is a temporary place.Librefs must be 1 to 8 characters
var sepal_len sepal_wid ; long, must begin with a letter or underscore, and can contain only letters, numbers, or underscores.
class species; Chapter 2: Referencing Files and Setting Options
table (sepal_len sepal_wid)*species, mean stddev min max; -When you specify a system option, it remains in effect until you change the option or end your SAS session.
proc means data = fitness; -To print a summary of library contents with the CONTENTS procedure, use a period to append the _ALL_ option to the libref. Adding the
class weight; NODS option suppresses detailed information about the files.
proc univariate data = fitness; Chapter 4: Creating List Reports
var oxygenintake; - Which of the following statements selects from a data set only those observations for which the value of the variable Style is RANCH,
class timetorun; SPLIT, or TWOSTORY? where style in ('RANCH','SPLIT','TWOSTORY');
ods graphics on; -In a PROC SORT step, you specify the DATA= option to specify the data set to sort. The OUT= option specifies an output data set. The
proc reg data = test; required BY statement specifies the variable(s) to use in sorting the data.
model manatee = boat age/noint; In a PROC SORT step, you specify the DATA= option to specify the data set to sort. The OUT= option specifies an output data set. The
ods graphics off; required BY statement specifies the variable(s) to use in sorting the data.
proc sgplot data = reg; -In a PROC SORT step, you specify the DATA= option to specify the data set to sort. The OUT= option specifies an output data set. The
series x=boat y=yconst; required BY statement specifies the variable(s) to use in sorting the data.
series x=boat y=nconst/lineattrs =(color = red); Chapter 5: Creating SAS Datasets from Raw Data
scatter x=boat y=manatee; -Which SAS statement associates the fileref Crime with the raw data file C:\States\Data\Crime? a. filename crime 'c:\states\data\crime';
proc sql; -Like LIBNAME statements, FILENAME statements are global; they remain in effect until you change them, cancel them, or end your SAS
create table ex2e as session.
select pt_id, hosp, admdate, disdate, (disdate - admdate) + 1 as dur - The OBS= option in the INFILE statement enables you to process only records 1 through n.
length=4 label='length of stay' /*formating the Chapter 6: Understanding Data Step Processing
from work.admits -Syntax checking can detect many common errors, but it cannot verify the values of variables or the correctness of formats
where calculated dur ge 14; -The DATA step executes once for each record in the input file, unless otherwise directed.
quit; -The remaining variables are initialized to missing. Missing numeric values are represented by periods, and missing character values are
-The WHERE clause can only be used on original variables not computed variables. To subset represented by blanks.
using computed variables, use the CALCULATED option: -The default value of _ERROR_ is 0, which means there is no error. When an error occurs, whether it is one error or multiple errors, the
-Cannot use WHERE statement when GROUPBY is in effect: value is set to 1.
proc sql; -By default, at the end of the DATA step, the values in the program data vector are written to the data set as an observation, the value
title "FULL outer join"; of the automatic variable _N_ is incremented by one, control returns to the top of the DATA step, and the values of variables created in
select coalesce(w.city,d.city), JanTemp,JulyTemp, programming statements are set to missing. The automatic variable _ERROR_ retains its value.
Education, income from SMSA_subset_weather2 as w -The order in which variables are defined in the DATA step determines the order in which the variables are stored in the data set.
full join -When SAS can't interpret syntax errors, the DATA step compiles, but it does not execute.
SMSA_subset_demog2 as d Chapter 10: Creating and Managing Variables
on w.city=d.city; -The Sum statement treats the missing value as a 0, so the value of Count in the fourth observation would be 10+20+0+40, or 70
Quit; -The RETAIN statement assigns an initial value of 100 to the variable Count, so the value of Count in the third observation would be
proc sql; 100+10+20+0, or 130.
title "inner join"; Chapter 11: Reading SAS Datasets
select w.city,JanTemp,JulyTemp,Education,income from -The DATA step executes once for each observation in the input data set. You use the POINT= option with the STOP statement to prevent
SMSA_subset_weather2 as w,SMSA_subset_demog2 as d continuous looping.
where w.city=d.city; Program : data work.getobs5(drop=obsnum); obsnum=5; set company.usa(keep=manager payroll) point=obsnum; output; stop; run;
Quit; Output: a data set that contains one observation
Misc: Program: data work.getobs5(drop=obsnum); obsnum=5; set company.usa(keep=manager payroll) point=obsnum; stop; run;
-Labels (and formats) created in a procedure is good only for the procedure and do not Output: an empty data set
carry forward. Use DATA step instead. Chapter 12 : Combining SAS DataSets
-SAS statements are not case-sensitive. -The two input data sets are not sorted by values of the BY variable, so the DATA step produces errors and stops processing.
-There are two types of comments used in SAS programs: Chapter 14: Generating Data with Do Loops
Block commenting using /* and */ -DO loops are DATA step statements and cannot be used in conjunction with PROC steps.
Line commenting using * . Note that the line commenting requires a semicolon at -The number of iterations is determined by the DO statements stop value, which in this case is 12.
the end * one covariate in the model is age ; . -At the end of the fifteenth iteration of the DO loop, the value for Year is incremented to 2005. Because this value exceeds the stop
-Creating a Raw Data File: When the goal of your SAS program is to create a raw data file value, the DO loop ends. At the bottom of the DATA step, the current values are written to the data set
and not a SAS data set, use the keyword _NULL_,. A SET statement specifies the SAS data set Chapter 15: Processing Arrays
that you want to read from. You can use the FILE and PUT statements to write out the -A SAS array exists only for the duration of the DATA step.
observations from a SAS data set to a raw data file the same way you used the INFILE and -An ARRAY statement is not an executable statement; it merely defines an array.
INPUT statements to create a SAS data set. -array goal{4} g1 g2 g3 g4 (initial values);
-Column input is appropriate only in some situations. When you use column input, your data
must be standard character or numeric values, and they must be in fixed fields. That is,
values for a particular variable must be in the same location in all records.

Você também pode gostar