BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AndersS
Lapis Lazuli | Level 10

Hi! My question:

Is it fast to write:  If   LNum LE   Xi  LT   UNum then do; .... end;

 

or is it better to write:

If   Xi  LT  UNum  then do;

     If LNum LE  Xi then do;      ........  end;

end;

 

This is a simplified part of the real problem:

 If   L1Num LE   Xi  LT   U1Num then do; ....;  GOTO Readnext; end;
 If   L2Num LE   Xi  LT   U2Num then do; ....;  GOTO Readnext; end;

If   L3Num LE   Xi  LT   U3Num then do; ....;  GOTO Readnext; end;
If   L4Num LE   Xi  LT   U4Num then do; ....;  GOTO Readnext; end;

etc.

If the condition is TRUE, then I want to execute the statements in the do-end. The last statement is a jump out GOTTO Readnext; to read/fetch new data values.

 

There is also a Select statment in SAS:

Select;

   when (L1Num LE   Xi  LT   U1Num)  do; ....;  GOTO Readnext; end;
   
when (L2Num LE   Xi  LT   U2Num)  do; ....;  GOTO Readnext; end;
   when (L3Num LE   Xi  LT   U3Num)  do; ....;  GOTO Readnext; end;
   when (L4Num LE   Xi  LT   U4Num)  do; ....;  GOTO Readnext; end;

   otherwise;

end;

 

I am using SAS ODA (SAS on a Linux computer). Quite good. BUT the cpu-times differ with 5-10% between different runs, a few minutes earlier. This means that it is "slightly difficult" to compare the cpu-times.
I have lots and lots of data and many, many if-statements /Br AndersS

Anders Sköllermo (Skollermo in English)
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I doubt it matters.  The extra code to implement the extra IF probably erases any gain from eliminating one of the comparisons.

 

If you only want to run ONE of the DO/END blocks then use IF/THEN/ELSE IF .... logic. 

if (L1Num LE Xi LT U1Num) then do; ....; end;
else if (L2Num LE Xi LT U2Num) then do; ....; end;
else if (L3Num LE Xi LT U3Num) then do; ....; end;
else if (L4Num LE Xi LT U4Num) then do; ....; end;

That will more closely match the SELECT pattern.

 

But why do you think you need to use GOTO?

Are you not just going to the next statement after the IF/SELECT block?

 

And what is READNEXT?  A data step will automatically loop over its inputs.  Why would you need to "read" some "next" something or other?

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

I doubt it matters.  The extra code to implement the extra IF probably erases any gain from eliminating one of the comparisons.

 

If you only want to run ONE of the DO/END blocks then use IF/THEN/ELSE IF .... logic. 

if (L1Num LE Xi LT U1Num) then do; ....; end;
else if (L2Num LE Xi LT U2Num) then do; ....; end;
else if (L3Num LE Xi LT U3Num) then do; ....; end;
else if (L4Num LE Xi LT U4Num) then do; ....; end;

That will more closely match the SELECT pattern.

 

But why do you think you need to use GOTO?

Are you not just going to the next statement after the IF/SELECT block?

 

And what is READNEXT?  A data step will automatically loop over its inputs.  Why would you need to "read" some "next" something or other?

AndersS
Lapis Lazuli | Level 10
Many Thanks. /Br AndersS
Anders Sköllermo (Skollermo in English)

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 623 views
  • 0 likes
  • 2 in conversation