how to set/merge tables like this?

Reply
Contributor
Posts: 46

how to set/merge tables like this?

Header 1Header 2Header 3
resultidincome estimation
result1145
result1246
result1344
result2136
result2245
result2348
result3142
result3241
result3342

how to let the above table become a table like this?

idresult1 result2result3
1453642
2464541
3444842

so I have 3 means that used to do income estimation.  However, after the calculation, I had a table looks like the top most table.  I just wanted to have a nice way to manage the table of comparison.

can anybody nicely let me know how to convert the table that way desired?  thanks.

Super Contributor
Posts: 1,636

Re: how to set/merge tables like this?

try the code below:

proc sort data=have;

by id result;

run;

proc transpose data=have out= want(drop=_Smiley Happy prefix=result;

by id result;

var income;

run;

/* sorry Lulus, the code above does not give you what you want , try the code below.  */

data have;

input id result $ income;

cards;

1 r1 20

2 r1 22

3 r1 26

1 r2 25

2 r2 28

3 r2 29

1 r3 40

2 r3 50

3 r3 60

;

proc sort data=have;

by id result;

run;

proc transpose data=have out= want(drop=_Smiley Happy ;

by id ;

id result;

var income;

run;

proc print data=want;run;

                            Obs    id    r1    r2    r3

                             1      1    20    25    40

                             2      2    22    28    50

                             3      3    26    29    60

Thank you Astounding!!!

Contributor
Posts: 46

Re: how to set/merge tables like this?

Thanks a lot.  I will try it and come back mark your solution as a correct one.  Have a good day!

Super User
Posts: 5,505

Re: how to set/merge tables like this?

If you have any trouble, here's another variation to try:

proc sort data=have;

  by id;

run;

proc transpose data=have out=want (drop=_Smiley Happy;

   by id;

   id result;

   var income;

run;

Good luck.

Ask a Question
Discussion stats
  • 3 replies
  • 216 views
  • 3 likes
  • 3 in conversation