BookmarkSubscribeRSS Feed
Kiteulf
Quartz | Level 8

Hi

 

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=?);
4 REPLIES 4
ballardw
Super User

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?

Kiteulf
Quartz | Level 8

 

 

Should be in a dataset as I am using the data as a benchmark

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:
proc freq...;

  var _numeric_;

run;

For example.

Kiteulf
Quartz | Level 8

Sorry guys

 

I fixed it with a ods output and a proc freq.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 955 views
  • 2 likes
  • 3 in conversation