BookmarkSubscribeRSS Feed
apple
Calcite | Level 5

Hi

 

Using SAS 7.1.

 

I don't understand how the below loop works.

Does the "Leave" indicate the loop will be exited once a missing TYP is found?

 

For Eg if I=14 --> TYP(14)=missing, then IK=15.

 

It won't continue to see if TYP(13), TYP(12), ...TYP(1), has missing values. Thank you

 

 

DO I = 15 TO 1 BY -1;
        IF MISSING(TYP{I}) THEN DO;
                IK = I + 1;
                LEAVE;
        END;
END;
 
 

 

2 REPLIES 2
LinusH
Tourmaline | Level 20
Documentation is quite clear :
"You can use the LEAVE statement to exit a DO loop or SELECT group prematurely based on a condition."
So, yes.
Data never sleeps
FreelanceReinh
Jade | Level 19

It should be noted that the LEAVE statement is not valid within a non-looping/non-iterative DO-END block (an error message would occur!), unless this block is in turn located in a SELECT-END block or in a DO loop (as in your example).

 

In the latter situation, both the remaining iterations of the DO loop and the statements following the LEAVE statement in the DO-END block (if any) are skipped.


In your example (with missing TYP{14} and provided that TYP{15} is not missing) IK is set to 15 and no further IF-checks are performed.

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
  • 2 replies
  • 1201 views
  • 0 likes
  • 3 in conversation