Reeza was so kind to help me with some coding but I did not give her everything I had in the table. Sorry. I have tried various ways to make this work with the addtl items I have in my data have. Her code worked perfect but after I looked at it I realized that I have other columns that do not use the mbr as the denom. Her base code is:
data cardiac.pos_final;
set cardiac.pos_aggregates;
array vars(*) ofc: ip: op:;
do i=1 to dim(vars);
location=scan(vname(vars(i)), 1, "_");
procedure=scan(vname(vars(i)), 2, "_");
value=vars(i);
value_display=put(value, 5.)||"/"||put(mbr, 5.);
output;
end;
drop ofc: ip: op:;
run;
But that takes columns that are to be with other columns and puts mbr as if it is the denom, which for these certain columns is not correct. I have
attached the need and have. I tried doing an if statement and it will run but the output is not right.
data cardiac.pos_final;
set cardiac.pos_aggregates;
array vars(*) ofc: ip: op:;
do i=1 to dim(vars);
location=scan(vname(vars(i)), 1, "_");
procedure=scan(vname(vars(i)), 2, "_");
value=vars(i);
if procedure = 'ofc_pcifu30' then
value_display=put(ofc_pcifu30, 5.)||"/"||put(ofc_pcifu30denom, 5.);
else if procedure = 'ofc_outptpci' then
value_display=put(ofc_outptpci, 5.)||"/"||put(ofc_pci, 5.);
else if procedure = 'ofc_pcifu182' then
value_display=put(ofc_pcifu182, 5.)||"/"||put(ofc_pcifu182denom, 5.);
else if procedure = 'ofc_majrestudy' then
value_display=put(ofc_majrestudy, 5.)||"/"||put(ofc_pcidenom, 5.);
else if procedure = 'ofc_minrestudy' then
value_display=put(ofc_minrestudy, 5.)||"/"||put(ofc_pcidenom, 5.);
else if procedure = 'ip_pcifu30' then
value_display=put(ip_pcifu30, 5.)||"/"||put(ip_pcifu30denom, 5.);
else if procedure = 'ip_outptpci' then
value_display=put(ip_outptpci, 5.)||"/"||put(ip_pci, 5.);
else if procedure = 'ip_pcifu182' then
value_display=put(ip_pcifu182, 5.)||"/"||put(ip_pcifu182denom, 5.);
else if procedure = 'ip_majrestudy' then
value_display=put(ip_majrestudy, 5.)||"/"||put(ip_pcidenom, 5.);
else if procedure = 'ip_minrestudy' then
value_display=put(ip_minrestudy, 5.)||"/"||put(ip_pcidenom, 5.);
else if procedure = 'op_pcifu30' then
value_display=put(op_pcifu30, 5.)||"/"||put(op_pcifu30denom, 5.);
else if procedure = 'op_outptpci' then
value_display=put(op_outptpci, 5.)||"/"||put(op_pci, 5.);
else if procedure = 'op_pcifu182' then
value_display=put(op_pcifu182, 5.)||"/"||put(op_pcifu182denom, 5.);
else if procedure = 'op_majrestudy' then
value_display=put(op_majrestudy, 5.)||"/"||put(op_pcidenom, 5.);
else if procedure = 'op_minrestudy' then
value_display=put(op_minrestudy, 5.)||"/"||put(op_pcidenom, 5.);
else if procedure = ' ' then
value_display=put(value, 5.)||"/"||put(mbr, 5.);
output;
end;
drop ofc: ip: op:;
run;
I sure wished I could research online for answers or use these SAS books but they are so limited in what they offer.
Break the array up into sections is one way.
For each case where the denominator changes use a different set of array/do loop/output section.
*All that have mbr in the denominator;
array vars(*) var1 var2 var3 var4 ...; *List only the numerators that will have MBR as the denominator here;
do i=1 to dim(vars);
location=scan(vname(vars(i)), 1, "_");
procedure=scan(vname(vars(i)), 2, "_");
value=vars(i);
value_display=put(value, 5.)||"/"||put(mbr, 5.);
output;
end;
*repeat with next denominator, controlling the list to specify your second denominator;
array vars2(*) var1 var2 var3 var4 ...; *List the variables here that will have the next denominator;
do i=1 to dim(vars2);
location=scan(vname(vars2(i)), 1, "_");
procedure=scan(vname(vars2(i)), 2, "_");
value=vars2(i);
value_display=put(value, 5.)||"/"||put(next_denominator, 5.);
output;
end;
Break the array up into sections is one way.
For each case where the denominator changes use a different set of array/do loop/output section.
*All that have mbr in the denominator;
array vars(*) var1 var2 var3 var4 ...; *List only the numerators that will have MBR as the denominator here;
do i=1 to dim(vars);
location=scan(vname(vars(i)), 1, "_");
procedure=scan(vname(vars(i)), 2, "_");
value=vars(i);
value_display=put(value, 5.)||"/"||put(mbr, 5.);
output;
end;
*repeat with next denominator, controlling the list to specify your second denominator;
array vars2(*) var1 var2 var3 var4 ...; *List the variables here that will have the next denominator;
do i=1 to dim(vars2);
location=scan(vname(vars2(i)), 1, "_");
procedure=scan(vname(vars2(i)), 2, "_");
value=vars2(i);
value_display=put(value, 5.)||"/"||put(next_denominator, 5.);
output;
end;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.