turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Data Step Multiple If's

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 11:18 AM - edited 02-12-2016 11:20 AM

Where online can i see an explaination of how multiple IF's are handled like below.

Thanks!

data base(keep = proposal_nbr tar_file tar_dt the_dt); merge base(in=ok1) prop_list(in=ok2); by proposal_nbr; if ok1; if the_dt eq . then the_dt=tar_dt; if the_dt lt date()-21;

The first one "gates" if an output is created, so if it misses, the last IF gets a chance to create an output?

Is that the proper way to look at this?

Also, does it matter that the line "the_dt=tar_dt" isn't higher up in the code?? Does it only take-effect from that point downward?

Accepted Solutions

Solution

02-12-2016
12:51 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 12:38 PM

Yes.

You just need to read about IF Statement, Subsetting, and understand what it is equivalent to.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 11:29 AM

The statement IF OK1; is a subsetting if, meaning that output will meet that requirement.

The Order of most statements in the code is very important. In your example the effect of

if the_dt eq . then the_dt=tar_dt;

would not matter as long as it appears between the MERGE (which apparently brings in the values for the variable the_dt) and

the** if the_dt lt date()-21; **where the newly assigned value would be used.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 12:11 PM

so what would this do?

data out;

set in;

if a;

if b;

if c;

Is this the same as "if a and b and c" then output?

Solution

02-12-2016
12:51 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 12:38 PM

Yes.

You just need to read about IF Statement, Subsetting, and understand what it is equivalent to.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-12-2016 02:46 PM

And regarding using "subsetting if" with "Merge" statment and how that work. Check "ONE-TO-ONE MATCH-MERGE KEEPING SOME OBSERVATIONS " in this paper SAS® DATA Step Merge – A Powerful Tool