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

Hello,

 

How can I include both a continuous and categorical variable (class) variable in the GAMPL procedure? 

 

I want to fit a spline for a year effect in Proc GAMPL (SAS 9.4 TS Level 1M5) to some time series data sets from different locations.  I have time series from different sites and would like to include all sites in 1 analysis and check for differences among sites (e. g., if residual analysis showed that some sites tended to be above zero and other sites below) and account for these in the fitted model.  Is this possible and what would the syntax look like?  I am aware that a class statement can be used in the Procedure but can’t find some examples either in Proc GAMPL or Proc GAM.  Some code I am using for the fit of the time series (without the class variable) and creating plots is below.

 

Thanks for any suggestions.

 

Best regards

bmac1

 

///////////////////////////////////

 

proc gampl data = new plots=components;

  model lncpue = spline(year) ;

  output out = fit pred upper lower resid;

run;

 

data new1;

   merge new fit;

run;

 

proc sgplot data=new1 noautolegend;

   band x=year lower=Lower upper=Upper;

   scatter x=year y=lncpue;

   series x=year y=Pred;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

All you need is the CLASS statement and include the class variable in a PARAM expression: And don't forget to SORT the data before you try to plot it, as discussed in the last section of "3 ways to add confidence limits to regression curves in SAS."

In fact, you can almost cut and paste the program from that blog post.

 

%let ClassVar = Sex;
%let YVar = Weight;
%let XVar = Height;

proc gampl data = sashelp.class plots=components;
  class &ClassVar;
  model &YVar = param(&ClassVar) spline(&XVar) ;
  output out = fit pred upper lower;
run;

data new1;
   merge sashelp.class fit;
run;

proc sort data=new1;
by &ClassVar &XVar;
run;

proc sgplot data=new1 noautolegend;
   band x=&XVar lower=Lower upper=Upper / group=&ClassVar transparency=0.5;
   scatter x=&XVar y=&YVar/ group=&ClassVar;
   series x=&XVar y=Pred / group=&ClassVar;
run;

 

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

All you need is the CLASS statement and include the class variable in a PARAM expression: And don't forget to SORT the data before you try to plot it, as discussed in the last section of "3 ways to add confidence limits to regression curves in SAS."

In fact, you can almost cut and paste the program from that blog post.

 

%let ClassVar = Sex;
%let YVar = Weight;
%let XVar = Height;

proc gampl data = sashelp.class plots=components;
  class &ClassVar;
  model &YVar = param(&ClassVar) spline(&XVar) ;
  output out = fit pred upper lower;
run;

data new1;
   merge sashelp.class fit;
run;

proc sort data=new1;
by &ClassVar &XVar;
run;

proc sgplot data=new1 noautolegend;
   band x=&XVar lower=Lower upper=Upper / group=&ClassVar transparency=0.5;
   scatter x=&XVar y=&YVar/ group=&ClassVar;
   series x=&XVar y=Pred / group=&ClassVar;
run;

 

 

bmac1
Obsidian | Level 7

Hi Rick_SAS,

 

Great, thank you!  This worked nicely!

 

Best regards

bmac1

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 431 views
  • 1 like
  • 2 in conversation