Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Re: Proc GAMPL using continuous and categorical (class) variables

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-13-2020 07:21 AM
(441 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Rick_SAS,

Great, thank you! This worked nicely!

Best regards

bmac1

**Available on demand!**

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

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.