Hello first time posting so go easy on me. I have a list of 50 or so dependent variables that I want to run in 3 different scenarios using proc logistic, so 150 rows. I don’t want to enter any data manually. I am manipulating the data in SAS to get the output table I desire.
This macro should loop through all the dependent variables and append the data to my base table but I cannot get it to work. Macro is below after description of the problem.
If I run the macro one variable at a time, I get this table which IS what I want, but this is dumb and time consuming.
The table gives me the odds ratios, confidence intervals and p-values for values 0 and 2 of the dependent variable (1 = referent group). Dependent variable is "depvar"
%mylogit2(stress_echo3 );
%mylogit2(oth_imaging3 );
%mylogit2(cabg3);
%mylogit2(pci3 );
DEPVAR
OR_0
P_0
OR_2
P_2
anyevent3
1.05 (0.88-1.25)
0.107
0.83 (0.65-1.07)
0.082
stress_echo3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
oth_imaging3
0.99 (0.80-1.22)
0.495
0.85 (0.63-1.15)
0.271
cabg3
0.58 (0.25-1.36)
0.335
0.78 (0.25-2.41)
0.959
pci3
0.58 (0.25-1.36)
0.335
0.78 (0.25-2.41)
0.959
pci3
0.97 (0.62-1.51)
0.878
1.01 (0.55-1.84)
0.943
When I run the macro this way - which is how I want to do this, I get the following. It does not take any additional data after
stress_echo3, it just appends the same data over and over again.
%mylogit2(stress_echo3 oth_imaging3 cath3 cabg3 pci3);
DEPVAR
OR_0
P_0
OR_2
P_2
anyevent3
1.05 (0.88-1.25)
0.107
0.83 (0.65-1.07)
0.082
stress_echo3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
oth_imaging3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
cath3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
cabg3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
pci3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
ami3
0.92 (0.50-1.69)
0.865
0.76 (0.30-1.91)
0.598
Here is the macro:
%macro mylogit2(all_deps);
ods output parameterestimates = pe (where=(variable ne "INTERCEPT"));
ods output oddsratios = or;
%let k=1;
%let dep = %scan(&all_deps, &k);
%do %while(&dep NE);
title 'Nuclear Cohort';
proc logistic data=logit ;
class accred_nuclear2 (ref='1');
model &dep (event=last) = accred_nuclear2 /lackfit;
where test = 2;
run;
*get the p-value;
data pe2;
set pe (keep=probchisq CLASSVAL0);
length depvar $20.;
depvar = "&dep";
accred=input(CLASSVAL0, 8.);
drop CLASSVAL0;
rename probchisq=p;
proc sort;
by accred;
run;
*Get the odds ratios and confidence intervals;
data or2;
set or;
length depvar $20.;
depvar = "&dep";
if effect = 'ACCRED_NUCLEAR2 0 vs 1' then accred = 0;
else if effect = 'ACCRED_NUCLEAR2 2 vs 1' then accred = 2;
depvar = "&dep";
drop effect;
Create a single variable that contains the string " oddsratio (lowerlimit CI - upperlimit CI) ';
o= strip(put(ODDSRATIOEST, 8.2));
u=strip(put(UPPERCL, 8.2));
l=strip(put(LOWERCL, 8.2));
ci = cats('(', l, '-', u, ')');
or = catx(' ' , o, ci);
keep or depvar accred;
proc sort;
by accred;
run;
*Create single file with p-value, ORs and CIs and flatten;
data f0 (keep=depvar or_0 p_0) f2 (keep=depvar or_2 p_2);
merge pe2 or2;
by accred;
if accred = 0 then do;
or_0 = or;
p_0 = round(p, 0.001);
output f0;
end;
if accred = 2 then do;
or_2 = or;
p_2= round(p, 0.001);
output f2;
end;
drop accred;
run;
*Create single row file with dependent variable, the OR, CI, and p-value variables for values 0 and 2 of the dependent variable.
data app_stats;
merge f0 f2;
by depvar;
run;
*Append to base table;
proc append base=stats
data=app_stats force;
run;
%let k = %eval(&k + 1);
%let dep = %scan(&all_deps, &k);
%end;
%mend;
/*this works*/
%mylogit2(stress_echo3 );
%mylogit2(oth_imaging3 );
%mylogit2(cabg3 pci3 );
%mylogit2(pci3 );
/*This does not work - all of the values are the same
it take the value of the first dependent variable only
and copies it all the way through. */
%mylogit2(stress_echo3 oth_imaging3 cath3 cabg3 pci3
ami3 cardiac_arrest3 hrt_failure3 h_angina3 h_other_hrt3 anycardiac_outcome);
... View more