Help using Base SAS procedures

merged datasets

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

merged datasets

I asked for help with a proc transpose and was told to create sep datasets and I did this but my proc transpose items are still not working the way they should with my merged datasets.

strataofc_cathsofc_pcisofc_sechoofc_tteofc_perfsop_cathsop_mpisop_tteip_ttembr
HAVE      3012322 21231
      894521136 29

WANTstrataprocofficeopip
30cath1/31/31/31
30pcis2/31/31/31
30secho3/31/31/31
30tte2/311/312/31
30perfs2/31/31/31
30mpis./312/31/31
89cath4/296/29/29
89pcis5/29/29/29
89secho2/29/29/29
89tte11/29/29/29
89perfs3/29/29/29
89mpis/29/29/29

I tried proc tranpose but that does not work, then tried a data step with if statements creating a new row called office, then 1 op and the other ip. It does not look like the want data.


Accepted Solutions
Solution
‎07-29-2013 05:50 PM
Super User
Posts: 19,780

Re: merged datasets

Here you go:

data want;

input strata    ofc_caths    ofc_pcis    ofc_secho    ofc_tte    ofc_perfs    op_caths    op_mpis    op_tte    ip_tte    mbr;

cards;

30    1    2    3    2    2    .    2    1    2    31

89    4    5    2    11    3    6    .    .    .    29

;

run;

data step1;

    set want;

    array vars(*) ofc: op: ip:;

    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, 2.)||"/"||put(mbr, 3.);

        output;

    end;

    drop ofc: op: ip:;

run;

proc sort data=step1;

by strata  procedure location;

run;

proc transpose data=step1 out=want;

by strata procedure;

id location;

var value_display;

run;

View solution in original post


All Replies
Solution
‎07-29-2013 05:50 PM
Super User
Posts: 19,780

Re: merged datasets

Here you go:

data want;

input strata    ofc_caths    ofc_pcis    ofc_secho    ofc_tte    ofc_perfs    op_caths    op_mpis    op_tte    ip_tte    mbr;

cards;

30    1    2    3    2    2    .    2    1    2    31

89    4    5    2    11    3    6    .    .    .    29

;

run;

data step1;

    set want;

    array vars(*) ofc: op: ip:;

    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, 2.)||"/"||put(mbr, 3.);

        output;

    end;

    drop ofc: op: ip:;

run;

proc sort data=step1;

by strata  procedure location;

run;

proc transpose data=step1 out=want;

by strata procedure;

id location;

var value_display;

run;

🔒 This topic is solved and locked.

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

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