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

Appreciate and thank you in advance for your help.

I want to do predictive numbers from the age groups as below in 2018:

<30 years: 200

30-39 years: 450

40-49 years: 330

50+ years: 175

In the next ten year (2028), assuming no deaths in each age group, if there is 25% in the age group <30 years will be aged 30-39 years, 25% in the age group 30-39 years will be aged 40-49 years, and 25% in the age group 40-49 years will be aged 50+ years. The bottom line is to estimate the number of those who are in the age group 50+ years. 

I use SAS studio. 

Phan S.

 

  

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Angel_Larrion
SAS Employee

Just work the result table a little more as follows.

proc sql;
create table want1 as
select group, coalesce(age30_2028,age39_2028,age49_2028,age50_2028) as people_2028
from want;
run;

data want_final;
set want1;
retain total;
total=sum(people_2028,total);
run;

the sum of all the groups is the one in the last row.

 

View solution in original post

10 REPLIES 10
Angel_Larrion
SAS Employee

The code is simple, but it should work.

data have;
input group :$15. People;
datalines;
30years 200
30-39years 450
40-49years 330
50+years 175
;
run;

data want;
set have nobs=count_obs;
retain val;
if group='40-49years' then val=people;
if group='50+years' then do;
people_2028=0.25*val+people; 
output; 
end;
keep group people_2028;
run;

The group of 40-49 years should be before the group if 50+.

PhanS
Obsidian | Level 7
Hi Angel,

I apply your code as below and it matches Excel outcomes.
Although the total is error - please see attached.
How to write a code for Total. Thank you.

data have;
input group :$15. People;
datalines;
30years 200
30-39years 450
40-49years 330
50+years 175
;
run;

data want;
set have nobs=count_obs;
retain val;
if group='30years' then val=people;
if group='30years' then do;
age30_2028=0.75*val;
end;
if group='30years' then val=people;
if group='30-39years' then do;
age39_2028=0.25*val+0.75*people;
end;
if group='30-39years' then val=people;
if group='40-49years' then do;
age49_2028=0.25*val+0.75*people;
end;
if group='40-49years' then val=people;
if group='50+years' then do;
age50_2028=0.25*val+people;
end;
total=age30_2028+age39_2028+age49_2028+age50_2028;
output;
keep group age30_2028 age39_2028 age49_2028 age50_2028 total;
run;
Angel_Larrion
SAS Employee

Just work the result table a little more as follows.

proc sql;
create table want1 as
select group, coalesce(age30_2028,age39_2028,age49_2028,age50_2028) as people_2028
from want;
run;

data want_final;
set want1;
retain total;
total=sum(people_2028,total);
run;

the sum of all the groups is the one in the last row.

 

PhanS
Obsidian | Level 7
Thank you, Angel.
Someone said I should do as a model calculation.
What do you think? If so, how can I write a model based on my dataset.

Phan S.
Angel_Larrion
SAS Employee

It can be done using Markov chains, but given the simplicity of the problem I wouldn't use that.

PhanS
Obsidian | Level 7
Angel,
In my dataset, I want to draw a graph to predict a 25%, 50% and 75%
increase for each age group.

I found this from SAS for Predictive values. I like the graph. I hope to
apply for my dataset.
But, I am not sure why I cannot run proc hpnlmod in my SAS Studio. The
Logfile says: Errors proc hpnlmod not found.

Please explain. May I apply this procedure for mine?

Thank you.

Phan S.
https://documentation.sas.com/?docsetId=stathpug&docsetTarget=stathpug_hpnlin_examples01.htm&docsetV...


data a;
input y x @@;
datalines;
.46 1 .47 2 .57 3 .61 4 .62 5 .68 6 .69 7
.78 8 .70 9 .74 10 .77 11 .78 12 .74 13 .80 13
.80 15 .78 16
;
run;
proc hpnlmod data=a out=b;
parms alpha=.45 beta=.05 gamma=-.0025;

x0 = -.5*beta / gamma;

if (x < x0) then
yp = alpha + beta*x + gamma*x*x;
else
yp = alpha + beta*x0 + gamma*x0*x0;

model y ~ residual(yp);

estimate 'join point' -beta/2/gamma;
estimate 'plateau value c' alpha - beta**2/(4*gamma);
predict 'predicted' yp pred=yp;
predict 'response' y pred=y;
predict 'x' x pred=x;
run;

proc sgplot data=b noautolegend;
yaxis label='Observed or Predicted';
refline 0.7775 / axis=y label="Plateau" labelpos=min;
refline 12.7477 / axis=x label="Join point" labelpos=min;
scatter y=y x=x;
series y=yp x=x;
run;


[image: image.png]
Angel_Larrion
SAS Employee

Its possible that you don't have the required license.

Check the the following link to see how to check that.

 

https://support.sas.com/kb/16/955.html 

PhanS
Obsidian | Level 7
I use SAS Edition.
May you be able to test for me, please.
I want to see a graph of the predict number 25%, 50% and 75% increase.
It is for my thesis work. If it works well I will use my real dataset.

Phan S.
Angel_Larrion
SAS Employee

I don´t have that product.

you could try making another post, maybe someone else can help you with that.

PhanS
Obsidian | Level 7
Ok, Thank you.

Phan S.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 10 replies
  • 1183 views
  • 0 likes
  • 2 in conversation