06-07-2016 11:48 AM - edited 06-07-2016 12:04 PM
I am trying to get a macro to loop thorugh a set of variables doing the same calculations. Here is what I have
And I am not sure if the Getvars and the macro varslist does work neither do the loop...(((
%Macro GetVars(PSI) ; %Local VarList ; /* open dataset */ %Let FID = %SysFunc(Open(&PSI)) ; /* If accessable, process contents of dataset */ %If &FID %Then %Do ; %Do I=1 %To %SysFunc(ATTRN(&FID,NVARS)) ; %Let VarList= &VarList %SysFunc(VarName(&FID,&I)); %End ; /* close dataset when complete */ %Let FID = %SysFunc(Close(&FID)) ; %End ; &VarList %Mend ; %DO_OVER(values= proc freq data=PSI; table ? /out=PSI_?_all noprint nocol nocum nopercent norow;run; proc freq data=PSI; table ?/out=PSI_?_bad noprint nocol nocum nopercent norow;where Bad_final=1;run; proc freq data=PSI_OOT; table ? /out=PSI_OOT_? all noprint nocol nocum nopercent norow;run; proc freq data=PSI_OOT; table ?/out=PSI_OOT_?_bad noprint nocol nocum nopercent norow;where Bad_final=1;run; Proc sql; Create table PSI_? as select t1.?, t1.Count as Dev, t1.Percent as Spread_DEV, t2.Count as OOT, t2.Percent as Spread_OOT, t3.Count as Bad_DEV, t3.Percent as Spread_Bad_DEV, t4.Count as Bad_OOT, t4.Percent as Spread_Bad_OOT from PSI_?_all as t1 left join PSI_OOT_?all as t2 on t1.? = t2.? left join PSI_?_bad as t3 on t1.? = t3.? left join PSI_OOT_?_bad as t4 on t1.? =t4.? ; QUIT; DATA PSI_?_1; SET PSI_?; PSI = ABS((Spread_DEV-Spread_OOT)*log(Spread_DEV/Spread_OOT))/100; PSI_bad = ABS((Spread_bad_DEV-Spread_bad_OOT)*log(Spread_bad_DEV/Spread_bad_OOT))/100; PSI_bad_error = PSI*PSI_bad*1000 ; Run; Proc Summary data=PSI_?_1 nway missing; VAR PSI PSI_bad PSI_bad_error; OUTPUT OUT=PSI_?_2 (drop=_FREQ_ _TYPE_) Sum=; Run; %DO_OVER(Values=varlist, PHRASE=?);
06-07-2016 11:54 AM - edited 06-07-2016 11:54 AM
How about providing a description of your input data, some example records in the form of a datastep so we can test code and what manipulation is needed and the desired output for the example data.
Since you apparently as a first step only counting the occurances of each value of the variables I'm pretty sure theres a better way but I can't figure out what you are attempting to do.
And does the result need to be in a dataset or is this for a report?
06-07-2016 12:12 PM
Am afraid I agree with @ballardw in that I have no idea what the above is trying to achieve. Post sample test data (in the form of a datastep) and what you want the output to look like. There is rarely a need to "loop over variables" as you call it, you can use by groups, and specify lists of variables or use automatics: