LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2012, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 7 Mar 2012 15:06:56 +0000
Reply-To:     "High, Robin R" <rhigh@UNMC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "High, Robin R" <rhigh@UNMC.EDU>
Subject:      Re: Example of generating Linear Interpolation
Comments: To: SAS_learner <proccontents@GMAIL.COM>
In-Reply-To:  <CAPo+ggs8qK1FcUj4cJq0Do0A+b1LeKM2sJV-V_QpK1MO-oae=w@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Some code I wrote several years ago to do not only linear interpolation, but depending on the number of input points, also does cubic, quadratic, etc.

Try it with these 4 data input values for x and y and observe the output:

1.1 10.6 1.5 2.1 2.1 25.2 3.0 20.3

Examples with more complex formulas may also be found in a numerical analysis book.

The down side of PROC EXPAND for interpolation (which I also endorse) is it expects inputs as SAS date variables. Most input data can be tweaked to represent "dates" but I agree an interpolation procedure in BASE that works with any data much like EXPAND does would be most welcome.

DATA tst; input x y; cards; 1.1 10.6 3.0 20.3 ;

PROC plot data=tst; PLOT y*x='+' / haxis = 1 to 3 by .5; options ps=40; RUN; quit;

* get the number of input values; data _null_ ; SET tst nobs=nn; CALL SYMPUTX("nn",nn); stop; run;

%put &nn.;

PROC TRANSPOSE DATA=tst out=x(drop=_name_) prefix=_x; var x; proc print; run; PROC TRANSPOSE DATA=tst out=y(drop=_name_) prefix=_y; var y; proc print; run;

DATA one; SET x ; SET y; KEEP x y_est; ARRAY xx(&nn.) _x1 - _x&nn. ; ARRAY yy(&nn.) _y1 - _y&nn. ; ARRAY nm(&nn.) xn1-xn&nn.; ARRAY dm(&nn.) xd1-xd&nn.;

* these are the x values to interpolate y;

DO x=1 to 3 by .1;

DO i = 1 to &nn.; nm{i}=1; dm{i}=1; DO j = 1 to &nn.; IF (j NE i) THEN DO; nm{i} = nm{i}*(x - xx{j}); dm{i} = dm{i}*(xx{i} - xx{j}); END; END; END; y_est=0; Do ii = 1 TO &nn.; y_est = y_est + (nm{ii} / dm{ii}) * yy {ii}; END; OUTPUT; END ;

RUN;

PROC PRINT data=one; VAR x y_est; RUN;

PROC plot data=one; PLOT y_est * x='+' / haxis = 1 to 3 by .2; options ps=40; RUN; quit;

Robin High UNMC

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of SAS_learner Sent: Tuesday, March 06, 2012 10:15 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Example of generating Linear Interpolation

Hello all ,

I need some help in SAS programming for one of my requirements, while deriving one of the Variables the specs read as

If MRIQS =TOTAL E SCORE, then use linear interpolation or extrapolation based on days from baseline and utilizing the baseline score and the non-missing post-baseline score

I do not have example of data to show too sorry. I do not have prior experience of working with Linear interpolation or extrapolation using SAS. When did google search for examples it pointed in using Proc Mixed and other procedures . Not sure where to look or how to start , I am reaching out to SAS-L for the some help in right direction . I greatly appreciate to answer any questions from my side to complete my task and eagerly looking forward for your answers.

Thanks SL


Back to: Top of message | Previous page | Main SAS-L page