Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Latent View SAS Training Feb 2009 - Day 6

Latent View SAS Training Feb 2009 - Day 6

Ratings: (0)|Views: 58|Likes:
Published by Amitmse

More info:

Published by: Amitmse on Jun 02, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

06/02/2011

pdf

text

original

 
Advanced SAS Training  Day 6
16 February 2009
1.
 
Difference between IF-THEN and %IF-%THEN:
y
 
IF-THEN construct can be used only in a DATA-SET step which is present either in opensource code (outside a macro), or within a macro.
y
 
Since in a DATA-SET step, observations are read and processed record by record, IF-THEN conditions will be applied and tested on every record, and output will begenerated record by record also.
y
 
IF-THEN/ELSE statement can contain only operands that are DATA step variables,character constants, numeric constants, or date and time constants.%IF-%THEN is used to conditionally process a portion of a macro.
y
 
%IF-%THEN construct cannot be used anywhere in open-source code. It can be usedonly in a macro, either in a DATA-SET step, or a procedure, or outside the two.
y
 
%IF-%THEN condition will be evaluated only for the condition(s) specified, and will notbe evaluated separately for every record. That is why it is very useful to use an %IF-%THEN statements to perform an entire DATA-STEP or procedure based on thefulfillment of the given condition(s).
y
 
%IF-%THEN/%ELSE statement can contain only operands that are constant text or textexpressions that generate text.Example:
Data
Id_Numbers;InputID;Datalines;12345;
RUN
;
%m 
acro
checkid();%letid=3;Data id_num_output1 id_num_output2;set Id_Numbers;
 
if id >
2
then outputid_num_output1;if &id >
2
then outputid_num_output2;run;
%mend 
;%
checkid 
;
P
ROC
 
P
RINT
 data=id_num_output1;
Ru
n
;
P
ROC
 
P
RINT
 data=id_num_output2;
Ru
n
;
 
 
2.
 
Difference Between DO-END and %DO-%END
DO designates the beginning of a section of a DATA-STEP, which is treated as a unit until amatching END statement is encountered.DO (Iterative) - END, DO-WHILE-END and DO-UNTIL-END have similar functionality as the DO-END statement, but additionally, can be used to process statements repeatedly as long as agiven condition is satisfied.
y
 
Each of the DO-END statements can be used only within a DATA-SET step, whether inopen source code, or within a macro.
y
 
They will be evaluated record by record in the DATA-SET step.
y
 
The index variable used in the DO(iterative) statement or Do-WHILE or DO-UNTILconstructs will get stored as a new variable in the data step in which it is beingprocessed.
y
 
The operand for a DO-WHILE or DO-UNTIL may also be a numeric DATA step variable,numeric constants, or date and time constants.The %DO statement designates the beginning of a section of a macro definition that is treated asa unit until a matching %END statement is encountered.%DO (Iterative) executes a section of a macro repetitively based on the value of an indexvariable.%DO-%WHILE and %DO-%UNTIL executes a section of a macro repetitively while, or until(respectively) a condition is true.
y
 
None of these statements can be used in open source code.
y
 
Within a macro, they can be used either outside a DATA-STEP or procedure, or insideeach of them.
y
 
They will be evaluated only for the specified condition, and not at a record by recordlevel.
y
 
The index variable used in a %DO (Iterative) statement will be stored as a macrovariable, but will not be stored as a dataset variable, even if this construct is used withina DATA-SET step.
 
y
 
Operands for %DO (iterative) , %DO-%WHILE and %DO-%UNTIL can only have operandsthat are integers or macro expressions that generate integers.e.g.
%m 
acro
checkid1();%doj=
1
 %to 
3
;Data id_num_output%eval(&j);set Id_Numbers;A
 
rray Score{
3
} $ ;do i=
1
to
3
;Score[i]="&j._"||put(i,
1.
);End;run;title Dataset Name -id_num_output%eval(&j);Proc Printdata=id_num_output%eval(&j);run;%end;
%mend 
;%
checkid1
;
 
3
.
 
Us
eful Option
s
in SAS:
a.
 
OBS= <integer value> |MIN | MAX;Is used to specify which observation of a dataset SAS processes last.MIN sets the number of the last observation to process to 0. Use OBS=0 in order tocreate an empty data set that has the structure, but not the observations, of anotherdata set.This option is very useful when you want to test the syntax of your code without havingto process each and every observation, and thus increase processing time. E.g.,
OB
S=
10
;

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->