<?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 Re: Cubic Spline interpolation - MANY variables at once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463161#M117951</link>
    <description>&lt;P&gt;This is pure gold. Works perfectly! Thank you so much!&lt;/P&gt;</description>
    <pubDate>Thu, 17 May 2018 21:06:14 GMT</pubDate>
    <dc:creator>SASaholic629</dc:creator>
    <dc:date>2018-05-17T21:06:14Z</dc:date>
    <item>
      <title>Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463078#M117921</link>
      <description>&lt;P&gt;I have 500 or so variables that each has 11 points of data. I need to cubic spline between those 11 points across 100 smaller intervals. And I need to do that for all 500 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this using some sort of LOOP? And is there a way to do it so that it automatically knows how many variables to do it for? i.e. this month I have 500 variables, but last month it was only 493 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Data:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA Have;&lt;BR /&gt;INPUT Percentile Var1 Var2 Var499 Var500;&lt;BR /&gt;DATALINES;&lt;BR /&gt;0.01 -950 400 300 650&lt;BR /&gt;0.02 . . . .&lt;BR /&gt;0.05 -600 150 200 450&lt;BR /&gt;0.10 -300 100 125 200&lt;BR /&gt;0.20 . . . .&lt;BR /&gt;0.25 . . . .&lt;BR /&gt;0.50 0 0 0 0&lt;BR /&gt;0.75 . . . .&lt;BR /&gt;0.80 . . . .&lt;BR /&gt;0.90 60 -225 -150 -375&lt;BR /&gt;0.95 180 -390 -300 -500&lt;BR /&gt;0.98 . . . .&lt;BR /&gt;0.99 400 -675 -450 -800&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to fill in the missing values by cubic splining. And I need to do it for Var1-Var500. And need to be able to easily account for more or less variables without manual intervention.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 17:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463078#M117921</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T17:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463082#M117922</link>
      <description>&lt;P&gt;transpose all VARs by percentile, sort by varname and percentile Then interpolate BY varname. Transpose back, if needed.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463082#M117922</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-17T18:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463084#M117923</link>
      <description>&lt;P&gt;How do you interpolate across by Varname? I only know how to interpolate going down:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC TRANSREG DATA=Have;&lt;/P&gt;&lt;P&gt;MODEL IDENTITY(Var1) =SMOOTH(Percentile/SM=0);&lt;/P&gt;&lt;P&gt;OUTPUT OUT=CubicSpline p;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463084#M117923</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T18:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463089#M117925</link>
      <description>&lt;P&gt;Using &lt;STRONG&gt;proc expand&lt;/STRONG&gt;, if you have the licence,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Have;
INPUT Percentile Var1 Var2 Var499 Var500;
DATALINES;
0.01 -950 400 300 650
0.02 . . . .
0.05 -600 150 200 450
0.10 -300 100 125 200
0.20 . . . .
0.25 . . . .
0.50 0 0 0 0
0.75 . . . .
0.80 . . . .
0.90 60 -225 -150 -375
0.95 180 -390 -300 -500
0.98 . . . .
0.99 400 -675 -450 -800
;

proc transpose data=have out=havet name=varname;
by percentile;
var var: ;
run;

proc sort data=havet; by varname percentile; run;

/* proc expand requires SAS/ETS licence */
proc expand data=havet out=haveExp factor=10;
by varname;
id percentile;
convert col1;
run;

proc sort data=haveExp; by percentile varname; run;

proc transpose data=haveExp out=want(drop=_name_);
by percentile;
var col1;
id varname;
run; 


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 May 2018 18:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463089#M117925</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-17T18:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463091#M117926</link>
      <description>&lt;P&gt;I was afraid&amp;nbsp;you were going to say that. I don't have the SAS/ETS license - might be time to petition for it though. Thanks, PG&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463091#M117926</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T18:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463094#M117927</link>
      <description>&lt;P&gt;Do you have SAS/IML?&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463094#M117927</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-17T18:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463095#M117928</link>
      <description>&lt;P&gt;I don't, but my colleague has that one (SAS/IML)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No one here has SAS/ETS&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463095#M117928</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T18:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463119#M117933</link>
      <description>&lt;P&gt;Do you want a cubic interpolating spline (goes through every data point) or a cubic smoothing spline (smooths the data, but does not always go through the points)?&amp;nbsp;If a smoothing spline is okay, does it have to be a spline? There are other nonpametric&amp;nbsp;smoothers such as loess and penalized B-splines that are more powerful because they automatically pick a smoothing parameter based on the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please read the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_langref_sect452.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;Cubic splines: interpolating vs smoothing&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2014/02/24/add-a-spline-to-a-scatter-plot.html" target="_self"&gt;Smoothing splines&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2014/02/26/how-to-automatically-select-a-smooth-curve-for-a-scatter-plot-in-sas.html" target="_self"&gt;Automatically select a smoother based on the data&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;My personal recommendation would be to use a loess or penalized B-spline.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you decide that PROC LOESS or PROC TRANSREG can fit the smoothers that you want, then the next step is to use the technique to&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_self"&gt;compute thousands of regression models&lt;/A&gt;&amp;nbsp;in SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463119#M117933</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-17T19:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463121#M117934</link>
      <description>&lt;P&gt;It has to be a cubic interpolating spline that goes through each of the known data points. The PROC TRANSREG I posted above is doing exactly what I need. Problem is that it only does it for one variable at a time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe I can use that and pair it with your link on how to compute thousands of regression models?&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463121#M117934</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T19:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463141#M117940</link>
      <description>&lt;P&gt;Yes. I think that will solve your problem. You transpose from wide to long format and then use BY processing to fit the 500 models. (The transpose will work on&amp;nbsp;arbitrary number of variables that have the same prefix, as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a little wrinkle: You want to score the models on a scoring data set. You haven't said what the scoring data looks like, but the code below scores all models on 101 points in the interval [0,1].&amp;nbsp; If you want each&amp;nbsp;variable&amp;nbsp;to be scored on different intervals (like [min, max]) then form the scoring data first and merge it into the long data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below follows my blog post but uses your data set. I changed the names of some variables because your explanatory variables use the prefix 'Var', so I made sure I didn't introduce new variables that have the same prefix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Long;
set Have;
array x [*] Var:;
/* the original data */
Orig = 1;
do vNum = 1 to dim(x);
   vName = vname(x[vNum]);  /* variable name in char var */
   Value = x[vNum];        /* value for each variable for each obs */
   output;
end;
Orig = 0;
/* the scoring data set ... or merge with scoring data later */
do vNum = 1 to dim(x);
   vName = vname(x[vNum]);     /* variable name in char var */
   Value = .;                  /* use missing values for scoring data */
   do Percentile = 0 to 1 by 0.1;   /* evenly spaced in [0,1] */
      output;
   end;
end;
drop Var:;
run;

/* 2. Sort by BY-group variable */
proc sort data=Long;  by vName Percentile;  run;

/* 3. Call PROC REG and use BY statement to compute all regressions */
options nonotes;
proc transreg data=Long noprint;
by vName;
MODEL IDENTITY(Value) =SMOOTH(Percentile/SM=0);
OUTPUT OUT=CubicSpline p;
RUN;
options notes;

/* for this small example with 4 variables, you can graph the results */
proc sgplot data=CubicSpline;
series x=Percentile y=PValue / group=vName;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 May 2018 20:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463141#M117940</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-17T20:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463149#M117944</link>
      <description>&lt;P&gt;My scoring data set isn't evenly spaced, so I'll have to merge that in. But I ran through your example and I'm pretty sure this is doing exactly what I need. Going to try to apply to my data and hopefully will be coming back here to mark this as the solution! Thanks, Rick&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 20:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463149#M117944</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T20:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cubic Spline interpolation - MANY variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463161#M117951</link>
      <description>&lt;P&gt;This is pure gold. Works perfectly! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 21:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cubic-Spline-interpolation-MANY-variables-at-once/m-p/463161#M117951</guid>
      <dc:creator>SASaholic629</dc:creator>
      <dc:date>2018-05-17T21:06:14Z</dc:date>
    </item>
  </channel>
</rss>

