Hi!
I would like some help trouble shooting a macro. I found this macro online for range checking my variables. I know there are a lot of ways to range check, but I am hoping to be abl eto build a spreadsheet to not values outside of my acceptable ranges. This one seems to work with that concepts, but I cannot get the macro to work with my sample data. I've also attached the pdf with the macro explained by the author. Any help is greatly appreciated!!
data rangetbl;
input @1 errorid $2.
@3 errorvar $12.
@15 errorsas $40.;
datalines;
1 usmil not(usmil in: (0,1))
2 usciv not(usciv in: (0,1))
3 nonusmil not(nonusmil in: (0,1))
4 nonusciv not(nonusciv in: (0,1))
5 EPW not (EPW in: (0,1))
;
run;
data dataset;
input
@1 medid 3.
@4 usmil 3.
@7 usciv 3.
@10 nonusmil 3.
@13 nonusciv 3.
@16 EPW 3.;
datalines;
1 0 0 1 1 2
2 1 0 1 0 0
3 3 1 2 0 0
4 0 2 1 0 0
;
run;
proc sort data=dataset;
by medid;
run;
data _null_;
set rangetbl end=last;
retain count;
if _n_=1 then count=0;
count=count+1;
call symput ('id'||left (trim(put(count,5.))),
trim (errorid));
call symput ('var'||left (trim(put(count,5.))),
trim (errorvar));
call symput ('code'||left (trim(put(count,5.))),
trim (errorsas));
if last then call symput
('checkct',left(trim(put(count,8.))));
run;
%macro checkvar (id, var, check);
if &check then do;
errorid="&id.";
errorvar="&var.";
errorval=&var;
output;
end;
%mend checkvar;
data error_ds (keep=medid errorid errorvar errorval);
set dataset;
length errorid errorvar $8 errorval 8.;
%macro runcheck;
%do j=1 %to &checkct;
%checkvar (%str (&&id&j),
%str (&&var&j)
%str (&&code&j));
%end;
%mend runcheck;
%runcheck;
run;
... View more