<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Proc GAMPL using continuous and categorical (class) variables in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/616888#M29727</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I include both a continuous and categorical variable (class) variable in the GAMPL procedure?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; 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.&amp;nbsp; Is this possible and what would the syntax look like?&amp;nbsp; 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.&amp;nbsp; Some code I am using for the fit of the time series (without the class variable) and creating plots is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;bmac1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;///////////////////////////////////&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;gampl&lt;/STRONG&gt; data = new plots=components;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model lncpue = spline(year) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out = fit pred upper lower resid;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; new1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge new fit;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sgplot&lt;/STRONG&gt; data=new1 noautolegend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; band x=year lower=Lower upper=Upper;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; scatter x=year y=lncpue;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; series x=year y=Pred;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 12:21:18 GMT</pubDate>
    <dc:creator>bmac1</dc:creator>
    <dc:date>2020-01-13T12:21:18Z</dc:date>
    <item>
      <title>Proc GAMPL using continuous and categorical (class) variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/616888#M29727</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I include both a continuous and categorical variable (class) variable in the GAMPL procedure?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; 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.&amp;nbsp; Is this possible and what would the syntax look like?&amp;nbsp; 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.&amp;nbsp; Some code I am using for the fit of the time series (without the class variable) and creating plots is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;bmac1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;///////////////////////////////////&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;gampl&lt;/STRONG&gt; data = new plots=components;&lt;/P&gt;&lt;P&gt;&amp;nbsp; model lncpue = spline(year) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out = fit pred upper lower resid;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; new1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge new fit;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sgplot&lt;/STRONG&gt; data=new1 noautolegend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; band x=year lower=Lower upper=Upper;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; scatter x=year y=lncpue;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; series x=year y=Pred;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 12:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/616888#M29727</guid>
      <dc:creator>bmac1</dc:creator>
      <dc:date>2020-01-13T12:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GAMPL using continuous and categorical (class) variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/616935#M29728</link>
      <description>&lt;P&gt;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 &lt;A href="https://blogs.sas.com/content/iml/2020/01/08/confidence-band-regression-sas.html" target="_self"&gt;"3 ways to add confidence limits to regression curves in SAS."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In fact, you can almost cut and paste the program from that blog post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ClassVar = Sex;
%let YVar = Weight;
%let XVar = Height;

proc gampl data = sashelp.class plots=components;
  class &amp;amp;ClassVar;
  model &amp;amp;YVar = param(&amp;amp;ClassVar) spline(&amp;amp;XVar) ;
  output out = fit pred upper lower;
run;

data new1;
   merge sashelp.class fit;
run;

proc sort data=new1;
by &amp;amp;ClassVar &amp;amp;XVar;
run;

proc sgplot data=new1 noautolegend;
   band x=&amp;amp;XVar lower=Lower upper=Upper / group=&amp;amp;ClassVar transparency=0.5;
   scatter x=&amp;amp;XVar y=&amp;amp;YVar/ group=&amp;amp;ClassVar;
   series x=&amp;amp;XVar y=Pred / group=&amp;amp;ClassVar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/616935#M29728</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-01-13T14:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc GAMPL using continuous and categorical (class) variables</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/618803#M29789</link>
      <description>&lt;P&gt;Hi Rick_SAS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great, thank you!&amp;nbsp; This worked nicely!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;bmac1&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 09:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-GAMPL-using-continuous-and-categorical-class-variables/m-p/618803#M29789</guid>
      <dc:creator>bmac1</dc:creator>
      <dc:date>2020-01-21T09:23:22Z</dc:date>
    </item>
  </channel>
</rss>

