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

Please clear my confusion on the below explained scenario

I have a dataset salary with below observations 

obs     salary

1         23456

2         12245

3         34500

4         44000

5         34435

 

i ran the below code

 

data tt;
do until(totalsal ge 50000);
set  salary;
totalsal + salary;
end;
run;

and i get result as:

 

obs      salary   totalsal

1         23456  23456

2         12245  35701

3         34500  70201

 

but when i ran the below code

data tt;
do until(totalsal ge 50000);
set  salary;
totalsal + salary;
output;
end;
run;

and i get result as:

 

obs      salary   totalsal

1         23456  23456

2         12245  35701

3         34500  70201

4         44000  114201

5         34435  148636

 

Please explain why is there a difference in the output, as i have already put the condition to continue the process only till

the "TOTALSAL" reaches 50000 or more?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The result from the first version of the code actually is:

 

obs salary totalsal
1 34500 70201
2 44000 114201
3 34435 148636

 

When a data step doesn't include an explicit OUTPUT statement, SAS inserts one right before the RUN statement. Thus, in your first version of the code, the OUTPUT is situated outside the DO UNTIL() loop. It will run after the UNTIL condition is met. In the second version of the code, the OUTPUT occurs explicitly within each iteration of the loop, whether the UNTIL condition is met or not.

PG

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Actually, you have asked a complex question.  Here's a program you can test to start moving in the right direction.  How does this DATA step end?

 

data tt;

put 'Next, SAS will execute the SET statement.';

set salary;

totalsal + salary;

run;

 

Important clue:  How many messages does the PUT statement write?

PGStats
Opal | Level 21

The result from the first version of the code actually is:

 

obs salary totalsal
1 34500 70201
2 44000 114201
3 34435 148636

 

When a data step doesn't include an explicit OUTPUT statement, SAS inserts one right before the RUN statement. Thus, in your first version of the code, the OUTPUT is situated outside the DO UNTIL() loop. It will run after the UNTIL condition is met. In the second version of the code, the OUTPUT occurs explicitly within each iteration of the loop, whether the UNTIL condition is met or not.

PG
monusing
Fluorite | Level 6

thanks for your reply @Astounding@PGStats

 

@PGStats, sorry for my mistake. the result is the same as you have mentioned.

Thanks for your explanation .

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 3309 views
  • 3 likes
  • 3 in conversation