Looping in SAS – DO Loops

BASIC LOOP

Created data set “S” and created variables i and y, as i moves from 1 to 10, y shows square of each observation in i.

INCREMENTING LOOP

Created data set “T” and created variables i and y, as i moves from 1 to 10, y shows square of each observation in i. This time, I have incremented  by 2. Now, i contains every 2nd number starting from 1 upto 10. y takes in values accordingly.

Suppose, we do not want variable i in the report. We can drop i and yet retain y. Created data set “U” and dropped i.


Created data set “V”. Added a variable num which increases by 2 each time the looping occurs.

V_LOOP_SAS

DECREMENTING LOOP

CONDITIONAL LOOP – UNTIL STATEMENT

UNTIL_LOOP_SAS

CONDITIONAL LOOP – WHILE STATEMENT

while_LOOP_SAS

ITERATIVE DO STATEMENTS WITH CONDITIONAL CLAUSES

DECREMENTING_LOOP_SAS


CREATING SAMPLES USING LOOPS

create_sample_LOOP_SAS

create_sample_LOOP_SAS

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s