Date: Sat, 18 Aug 2007 10:06:17 +0200
Reply-To: SAS-L List <sas-l@listserv.uga.edu>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Robert Bardos <bardos2@ANSYS.CH>
Subject: Re: Run Iterations more Efficiently
In-Reply-To: <1187384446.653010.71500@22g2000hsm.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
Pat,
generally: by far too many data steps!
You will gain a significant amount of time by simply reducing the number
and type of data steps.
Example 1: the code bit for the first four data/proc steps should be
reducable to a view followed by proc sort.
data test1_view / view = test1_view ;
set Pat.database ;
week1 = datepart(week) ;
format week1 date9. ;
run ;
proc sort data=test1_view out=test1 ;
by week ;
run ;
Example 2: the combination of macros ABLOG and CALCpred generates an
enormous number of data steps. This is where you lose most of the time. The
logic is too convoluted for me to invest more time here but since you are
constantly creating the same set of variables (SImp40, BFImp40, EImp40,
WImp40, HLImp40, WLImp40) over and over again I have the strong feeling
that *one* data step incorporating all of the looping logic *plus* a
"scenario identifier" variable should suffice. "scenario identifier" would
then be used as an additional class variable in proc summary.
Example 3: drop the datastep 'data test3' and use the where= dataset option
(which can be used with PROC statements as well).
proc summary data = test2 (where=(week1>'25dec2006'd)) NWAY;
class ID SID BFID EID WID HLID WLID;
VAR PU BU IU;
OUTPUT OUT=test4 SUM=PU BU IU;
RUN;
Example 4: do not append using a data step 'set test4 test5' technique. Use
proc append instead. So drop the datastep 'data test5'.
proc append base=Pat.test5 new=test4 ;
run ;
Sorry for not being able to help with the real beefy part (as outlined in
the "Example 2" paragraph).
PS: note that all of the code pieces above are untested.
Robert
> -----Ursprüngliche Nachricht-----
> Von: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]Im Auftrag von Pat
> Gesendet: Freitag, 17. August 2007 23:01
> An: SAS-L@LISTSERV.UGA.EDU
> Betreff: Run Iterations more Efficiently
>
>
> Hi,
> I wrote this code but it is taking a long time to run (because of
> lots of iterations) and I am sure it is not the most efficient. Can
> one of the gurus suggest anything to make it more efficient and run
> faster ? Any help will be greatly appreciated. Thanks very much in
> advance !
> Pat
>
>
> PROC PRINTTO LOG='NUL'; RUN;
>
> libname Pat "C:/mylib/SAS";
>
>
> data test;
> set Pat.database;
> run;
>
> data test;
> format Week DATETIME9;
> informat Week DATETIME18.;
> set test;
> run;
>
> proc sort data = test;
> by Week;
> run;
>
> data test1;
> format Week1 date9.;
> set test;
> Week1 = datepart(Week);
> run;
>
> %macro ABLOG(var1, n);
> data test1;
> set test1;
> if Week1 = '03JAN2000'd then &var1&n = 0.4*( &var1 );
> retain &var1&n;
> &var1&n = 0.4*( &var1 ) + 0.6*( &var1&n ) ;
> ln_&var1&n = log(1 + &var1&n );
> run;
> %mend ABLOG;
>
>
> %macro CALCPred(a,b,c,d,e,f);
> data test1;
> set test1;
> SImp = &a*SH/0.13998068799642300;
> BFImp = &b*BF/0.28250142769484600;
> EImp = &c*EP*(1/0.13940709183106700);
> WImp = &d*NW*(1/0.11239379027589400);
> HLImp = &e*HL*(1/0.15492664544454100 );
> WLImp = &f*WL*(1/0.17079035675722900 );
> %ABLOG(SImp, 40);
> %ABLOG(BFImp, 40);
> %ABLOG(EImp, 40);
> %ABLOG(WImp, 40);
> %ABLOG(HLImp, 40);
> %ABLOG(WLImp, 40);
> run;
>
> data test2;
> set test1;
> PU = ln_SImp40*158.622870415965 + ln_BFImp40*136.216474824687 +
> ln_EImp40*166.725187683255 + ln_WImp40*140.926947895956+
> ln_HLImp40*154.449993828086 + ln_WLImp40*143.217782500437;
> BU = ln_SH40*158.622870415965 + ln_BF40*136.216474824687 +
> ln_EP40*166.725187683255 + ln_NW40*140.926947895956+
> ln_HL40*154.449993828086 + ln_WL40*143.217782500437;
> IU = PU - BU;
> SID = &a;
> BFID = &b;
> EID = &c;
> WID = &d;
> HLID = &e;
> WLID = &f;
> run;
>
> data test3;
> set test2;
> if Week1 > '25DEC2006'd ;
> run;
>
> proc summary data = test3 NWAY;
> class ID SID BFID EID WID HLID WLID;
> VAR PU BU IU;
> OUTPUT OUT=test4 SUM=PU BU IU;
> RUN;
>
> data test5;
> set Pat.test5;
> run;
>
> data Pat.test5;
> set test5 test4;
> run;
>
> %mend CALCPred;
>
>
>
> %macro Iterat;
> %do a = 0 %to 100 %by 5;
> %let x = %eval(100 - &a);
> %do b = 0 %to &x %by 5;
> %let y = %eval(100 - &a - &b);
> %do c = 0 %to &y %by 5;
> %let z = %eval(100 - &a - &b - &c);
> %do d = 0 %to &z %by 5;
> %let v = %eval(100 - &a - &b - &c - &d);
> %do e = 0 %to &v %by 5;
> %let f = %eval(100 - &a -&b -&c -&d - &e);
> %CALCPred(&a, &b, &c, &d, &e, &f);
> run;
> %end;
> %end;
> %end;
> %end;
> %end;
> %mend Iterat;
>
> %Iterat;
> run;
>
>