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

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
Pyrite | Level 9
Many Thanks. /Br AndersS
Anders Sköllermo (Skollermo in English)

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 409 views
  • 0 likes
  • 2 in conversation