Hello,
I have a dataset:
| ID_1 | Value |
| A | 1 |
| A | 2 |
| A | 3 |
| B | 4 |
| B | 5 |
| B | 6 |
| C | 7 |
| C | 8 |
I want to make ID_1 unique and create new columns for all the values. So I want:
| ID_1 | Value_1 | Value_2 | Value_3 |
| A | 1 | 2 | 3 |
| B | 4 | 5 | 6 |
| C | 7 | 8 |
Hope someone can help me. Thanks!
data have;
input ID_1 $ Value;
cards;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
proc transpose data=have out=want prefix=value;
by id_1;
var value;
run;
data have;
input ID_1 $ Value;
cards;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
proc transpose data=have out=want prefix=value;
by id_1;
var value;
run;
Do like this
data have;
input ID_1 $ Value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
proc transpose data=have out=want(drop=_NAME_) prefix=value_;
by ID_1 ;
var Value;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.