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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

Yes.

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

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

 

cellurl
Quartz | Level 8

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?

mohamed_zaki
Barite | Level 11

Yes.

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

mohamed_zaki
Barite | Level 11

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1354 views
  • 0 likes
  • 3 in conversation