Help using Base SAS procedures

new dataset merge issue

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

new dataset merge issue

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.


Accepted Solutions
Solution
‎07-30-2013 12:57 PM
Super User
Posts: 19,875

Re: new dataset merge issue

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;



View solution in original post


All Replies
Solution
‎07-30-2013 12:57 PM
Super User
Posts: 19,875

Re: new dataset merge issue

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;



🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 160 views
  • 0 likes
  • 2 in conversation