Syntax, ID statement
in the PRINT procedure:
ID variable(s);
|
proc print data=cert.reps;
id idnum lastname;
run;
proc print data=cert.reps; id idnum lastname; /*#1*/ var idnum sex jobcode salary; /*#2*/ run;
1 | The ID statement replaces the OBS column in the output with the IDnum and LastName variable values. |
2 | The VAR statement selects the variables that appear in the output and determines the order. |
Syntax, WHERE statement:
WHERE where-expression;
|
proc print data=cert.admit; var age height weight fee; /*#1*/ where age>30; /*#2*/ run;
1 | The VAR statement selects the variables Age, Height, Weight, and Fee and displays them in the output in that order. |
2 | The WHERE statement selects only the observations for which the value of Age is greater than 30 and prints them in the output. |
Symbol
|
Meaning
|
Sample Program Code
|
---|---|---|
= or eq
|
equal to
|
where name='Jones, C.'; |
^= or ne
|
not equal to
|
where temp ne 212; |
> or gt
|
greater than
|
where income>20000; |
< or lt
|
less than
|
where partno lt "BG05"; |
>= or ge
|
greater than or equal
to
|
where id>='1543'; |
<= or le
|
less than or equal to
|
where pulse le 85; |
?
.
You can use either the CONTAINS keyword or the symbol in your code,
as shown below. where firstname CONTAINS 'Jon'; where firstname ? 'Jon';
Operator, Symbol
|
Description
|
|
---|---|---|
AND
|
&
|
and, both. If both expressions
are true, then the compound expression is true.
|
OR
|
|
|
or, either. If either
expression is true, then the compound expression is true.
|
where age<=55 and pulse>75; where area='A' or region='S'; where ID>'1050' and state='NC';
where actlevel='LOW' or actlevel='MOD'; where fee=124.80 or fee=178.20;
where actlevel in ('LOW','MOD'); where fee in (124.80,178.20);
where (age<=55 and pulse>75) or area='A'; where age<=55 and (pulse>75 or area='A');
Syntax, FIRSTOBS=, and
OBS= options in an OPTIONS statement:
FIRSTOBS=n
OBS=n
|
options obs=max;
options firstobs=10; /*#1*/ proc print data=cert.heart; /*#2*/ run;
1 | Use the OPTIONS statement to specify the FIRSTOBS= option. In this example, the FIRSTOBS=10 option enables SAS to read the 10th observation of the data set first and read through the last observation. |
2 | A total of 11 observations are printed using the PROC PRINT step. |
options firstobs=1 obs=10; /*#1*/ proc print data=cert.heart; /*#2*/ run;
1 | The FIRSTOBS=1 option resets the FIRSTOBS= option to the default value. The default value reads the first observation in the data set. When you specify OBS=10 in the OPTIONS statement, SAS reads through the 10th observation. |
2 | A total of 10 observations are printed using the PROC PRINT step. |
options firstobs=10 obs=15; /*#1*/ proc print data=cert.heart; /*#2*/ run;
1 | When you set FIRSTOBS=10 and OBS=15, the program processes only observations 10 through 15. |
2 | A total of six observations are printed using the PROC PRINT step. |
options firstobs=10 obs=15; proc print data=clinic.heart; run;
options firstobs=10 obs=15;
proc print data=clinic.heart(firstobs=20 obs=30);
run;