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!

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