BookmarkSubscribeRSS Feed
Greek
Obsidian | Level 7

Good morning,

I have the following code and a data set of 100 observations. I am asking for 5 loops so given the code below I would expect 505 obervations. Instead, I get 109 observations. Does anybody know why and how to fix it?

do year=1 to 5;

if age<(65-year) then numerator_factor=1; else numerator_factor=0;

denominator_factor=1;

denominator+denominator_factor;

numerator+numerator_factor;

Percentage=1-(Numerator/Denominator);

delete_dummy=1;

output;

if end; delete_dummy=0; percentage=percentage; output;

format percentage percent8.2;

end;

run;

Thank you!

3 REPLIES 3
Amir
PROC Star

Hi,

I think it would be easier if we saw the whole of your program and perhaps some data.

The 2nd output statement only gets executed if the condition "if end;" is satisfied, how many observations are you expecting that to be true for? It would have to be true for every observation for the 2nd output to be executed every time.

Regards,

Amir.

Message was edited by: Amir Malik - amended last line.

Tom
Super User Tom
Super User

There is a big difference between subsetting if like you are using (IF END;) and an IF/THEN conditional.  You probably want to change

if end; delete_dummy=0; percentage=percentage; output;

to

if end then do;

delete_dummy=0;

percentage=percentage;

output;

end;

Greek
Obsidian | Level 7

Good afternoon and thank you for your responses:

This is a partial dataset and the code:

I have three people, 63, 64, 65 years old.

ods html;

data employees;

input age @@;

datalines;

62 63 64

run;

I want to know what percentage of my workforce will retire in 1 year and in 2 years from now.

the variable percentage at delete_dummy=0 should give me the answer.  

data retirement;

set employees end=end;

do year=1 to 2;

if age<(65-year) then numerator_factor=1; else numerator_factor=0;

denominator_factor=1;

denominator+denominator_factor;

numerator+numerator_factor;

Percentage=1-(Numerator/Denominator);

delete_dummy=1;

output;

if end then do; delete_dummy=0; percentage=percentage; output;

end;

format percentage percent8.2;

end;

run;

proc print data=retirement;

run;

ods html close;

This is what I get

Obsageyearnumerator_factordenominator_factordenominatornumeratorPercentagedelete_dummy
162111110.00%1
262211220.00%1
363111330.00%1
4632014325.00%1
5641015340.00%1
6641015340.00%0
7642016350.00%1
8642016350.00%0

This is what I would like to get

Obsageyearnumerator_factordenominator_factordenominatornumeratorPercentagedelete_dummy
162111110.00%1
263111220.00%1
3641013233.33%1
4641013233.33%0
562211110.00%1
6632012150.00%1
7642013166.66%1
8642013166.66%0

Any ideas?

Thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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