BookmarkSubscribeRSS Feed
pamplemousse822
Obsidian | Level 7

i want to plot outcome over time using predicted outcomes for an "average" observation from a model with transformed time variables (time^2). This works if I include the transformed variable in the model without calling in a new variable (e.g., time time*time). How can I make this work if i want to call in a new variable (vs. time time_sq, where time_sq=time*time)? Thanks! 

	*version 1: age age*age.... code works!;
	proc genmod data=dat; 
		class idno male edu; 
		model score= age|x age*age male edu_4; 
		repeated subject=idno; 
		weight w;
		store contcont; 
	run;

	data scoredata; *set covs to ref or mean; 
		male=0;
		edu=0;
		do x = 12, 18;
		do age = 70 to 100 by 1; 
			output; 
		end; end;
	run; 

	proc plm source=contcont; 
		 score data=scoredata out=plotdata predicted=pred lclm=lower uclm=upper; 
	run; 

	proc sgplot data=plotdata; 
		band x=age upper=upper lower=lower / group=x transparency=0.5; 
		series x=age y=pred / group=x; 
		yaxis label="score"; 
	run;

Version 1 (age age*age in model)Version 1 (age age*age in model)

 

*version 2 (age age_sq)...code doesn't work;
	data dat2; 
		set dat; 
		age_sq=age*age; 
	run; 

	proc genmod data=dat2; 
		class idno male edu; 
		model score= age|x age_sq male edu_4; 
		repeated subject=idno; 
		weight w;
		store contcont; 
	run;

	data scoredata; *set covs to ref or mean; 
		male=0;
		edu=0;
		age_sq=6783; *mean value.. i have also tried omitting this and proc plm won't run because it needs all the variables;
		do x = 12, 18;
		do age = 70 to 100 by 1; 

			output; 
		end; end;
	run; 

	proc plm source=contcont; 
		 score data=scoredata out=plotdata predicted=pred lclm=lower uclm=upper; 
	run; 

	proc sgplot data=plotdata; 
		band x=age upper=upper lower=lower / group=x transparency=0.5; 
		series x=age y=pred / group=x; 
		yaxis label="score"; 
	run;

Version 2 (age age_sq in model)Version 2 (age age_sq in model)

4 REPLIES 4
sbxkoenk
SAS Super FREQ

Maybe I don't get it right ...

but shouldn't you replace (in your second code block) this piece of code

data scoredata; *set covs to ref or mean; 
	male=0;
	edu=0;
	age_sq=6783; *mean value.. i have also tried omitting this and proc plm won't run because it needs all the variables;
	do x = 12, 18;
	do age = 70 to 100 by 1; 

		output; 
	end; end;
run; 

with this piece of code

data scoredata; *set covs to ref or mean; 
	male=0;
	edu=0;
*age_sq=6783; *mean value.. i have also tried omitting this and proc plm won't run because it needs all the variables;
	do x = 12, 18;
	do age = 70 to 100 by 1; 
        age_sq = age*age;
		output; 
	end; end;
run; 

??

Koen

pamplemousse822
Obsidian | Level 7
yes that works! my issue is that i am trying to use splined terms, so i have new age variables, like age2, age3, age4 from proc transreg.... and i dont know how to incorporate those new terms.

ballardw
Super User

@pamplemousse822 wrote:
yes that works! my issue is that i am trying to use splined terms, so i have new age variables, like age2, age3, age4 from proc transreg.... and i dont know how to incorporate those new terms.


I don't think Proc PLM will allow you to use variables that weren't in the original model.

You may be skipping out  on a clear description of what you are attempting. Perhaps you want to rename Age2 as Age and run PLM to create set with that variable as the age? Then rename Age3 ?

You should be able to do that as a data set option on the SCORE statement.

Something like:

score data=yourdataset (rename=(age2=age)) out=age2_scored_set /*other score options*/ ;

 

sbxkoenk
SAS Super FREQ

@pamplemousse822 wrote:
yes that works! my issue is that i am trying to use splined terms, so i have new age variables, like age2, age3, age4 from proc transreg.... and i dont know how to incorporate those new terms.


There's no need to use PROC TRANSREG to construct your splined terms.
You can use the SPLINE option in the EFFECT statement to generate spline effects.
See here : 
Regression with restricted cubic splines in SAS
By Rick Wicklin on The DO Loop April 19, 2017
https://blogs.sas.com/content/iml/2017/04/19/restricted-cubic-splines-sas.html

 

See also this usage note :
Usage Note 57975: Understanding splines in the EFFECT statement
https://support.sas.com/kb/57/975.html

 

For even more info, go here :
https://blogs.sas.com/content/?s=effect+spline

 

Koen

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 639 views
  • 2 likes
  • 3 in conversation