BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jaliu
Quartz | Level 8

'The subsetting IF statement causes the DATA step to continue processing only those raw data records or those observations from a SAS data set that meet the condition of the expression that is specified in the IF statement. That is, if the expression is true for the observation or record (its value is neither 0 nor missing), SAS continues to execute statements in the DATA step and includes the current observation in the data set. The resulting SAS data set or data sets contain a subset of the original external file or SAS data set.

If the expression is false (its value is 0 or missing), no further statements are processed for that observation or record, the current observation is not written to the data set, and the remaining program statements in the DATA step are not executed. SAS immediately returns to the beginning of the DATA step because the subsetting IF statement does not require additional statements to stop processing observations.'

 

If the expression is false, why wouldn't further statements be processed for any observation? If we had multiple if statements and the first one were not met, wouldn't it then check to see if the second were met? In fact this is what happens, and it does not make sense that control (don't know what this actually means) would immediately return to the top of the data step instead of evaluating remaining statements. What am I misunderstanding?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@jaliu wrote:

 

If the expression is false, why wouldn't further statements be processed for any observation?  In fact this is what happens, and it does not make sense that control (don't know what this actually means) would immediately return to the top of the data step instead of evaluating remaining statements. What am I misunderstanding?


Why? Because that's how subsetting IF statements work.

 

If we had multiple if statements and the first one were not met, wouldn't it then check to see if the second were met?

No.

 

In fact this is what happens, and it does not make sense that control (don't know what this actually means) would immediately return to the top of the data step instead of evaluating remaining statements. What am I misunderstanding?

 

Apparently, you are misunderstanding the whole thing. Sometimes you can create simple examples to demonstrate concepts:

 

data class;
    set sashelp.class;
    if sex='F';
    if height>55;
run;

If the sex is equal to 'M' and processing stops for that observation and the observation is not output to data set CLASS. If the sex is equal to 'F' then the processing continues to the next IF statement and then those records for which height>55 are selected.

--
Paige Miller

View solution in original post

4 REPLIES 4
jaliu
Quartz | Level 8

I think I got this confused with an if/then statement which functions differently.

PaigeMiller
Diamond | Level 26

@jaliu wrote:

 

If the expression is false, why wouldn't further statements be processed for any observation?  In fact this is what happens, and it does not make sense that control (don't know what this actually means) would immediately return to the top of the data step instead of evaluating remaining statements. What am I misunderstanding?


Why? Because that's how subsetting IF statements work.

 

If we had multiple if statements and the first one were not met, wouldn't it then check to see if the second were met?

No.

 

In fact this is what happens, and it does not make sense that control (don't know what this actually means) would immediately return to the top of the data step instead of evaluating remaining statements. What am I misunderstanding?

 

Apparently, you are misunderstanding the whole thing. Sometimes you can create simple examples to demonstrate concepts:

 

data class;
    set sashelp.class;
    if sex='F';
    if height>55;
run;

If the sex is equal to 'M' and processing stops for that observation and the observation is not output to data set CLASS. If the sex is equal to 'F' then the processing continues to the next IF statement and then those records for which height>55 are selected.

--
Paige Miller
jaliu
Quartz | Level 8

yes, I figured it out. I got it confused with if/else. 

 

thanks

Reeza
Super User
In these cases, where you solve the issue yourself or realize it's a mistake, please still post the correct answer and then mark the question as answered. This will help prevent people from continuing to respond and leaves a trail for future users who may have the same question. One purpose of a community board is to leave a database of answered questions that users can search in the future.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 804 views
  • 1 like
  • 3 in conversation