Link to home
Start Free TrialLog in
Avatar of flyfishin4trout
flyfishin4trout

asked on

SAS Rows to Columns

I need to do the following in "SAS"  (Also the number of Meds will vary. So there might be 3, 10, 20, etc)
Take the example dataset from
ID Med
1    A  
1    B
1    C
2    D
3    A
3    C


To
ID   Med_1   Med_2   Med_3  
1      A             B         C
2      D
3      A             C


Thanks,
J
ASKER CERTIFIED SOLUTION
Avatar of wigmeister
wigmeister

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kumar1505
Kumar1505

Hi J

Here is the answer. Its simple code and exact solution to your problem. It creates "mid_" columns based on the values of ID column. If ID column has 10 unique values then there will be 10 "mid_" variables in the result dataset.

Regards
Kumar
proc transpose data=sample out=result prefix=mid_;
by id;
var med;
run;
 
If the dataset "sample" is not sorted:
 
proc sort data=sample;
by id;
run;
 
proc transpose data=sample out=result prefix=mid_;
by id;
var med;
run;

Open in new window

Proc transpose is definitely what he needed as was my suggestion.