Help using Base SAS procedures

Simple IF statement question

Reply
Contributor
Posts: 62

Simple IF statement question

Hi,

Within 2 weeks, I've got the Base exam. After reading a lot (don't have access to the actual SAS right now, so I can't find out this question for myself), I want to know what will happen with the following code if there are more statements between the IF statement and the RUN statement:

Data XX.YY
Input ...
If tolerance="D";
TotalTime=(Timemin*60)+timesec;

run;

Will all statements after the IF statement only execute when tolerance="D", or does the IF statement only applies to the variable assignment (Totaltime)?

To put it another way, what is the value of TEST when running this code when tolerance="A":

Data XX.YY
Input ...
If tolerance="D";
TotalTime=(Timemin*60)+timesec;
TEST=6;
run;

Thanks in advance!
SAS Super FREQ
Posts: 8,864

Re: Simple IF statement question

Hi:
That particular form of the IF statement (the one that looks like the front end of an IF statement) is called a "subsetting" IF. It acts like a funnel to the rest of the program. When an observation meets the subsetting IF condition, it is allowed passage through the funnel to the rest of the logic (and the output) in the program. When an observation does NOT meet the condition, it is essentially deleted from the input buffer and the next observation in the input file is read and continues to process. This means, for example, in your hypothetical case, that the data set XX.YY would NOT have -any- observations with TOLERANCE='A' (assuming that there were no explicit OUTPUT statements before the subsetting IF).

For a description of the subsetting IF, read this in the documentation:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000201978.htm

cynthia
Contributor
Posts: 62

Re: Simple IF statement question

Posted in reply to Cynthia_sas
Thank you very much for this info!!
Ask a Question
Discussion stats
  • 2 replies
  • 148 views
  • 0 likes
  • 2 in conversation