Hi I have a dataset in list format which is an output from powershell that I've cleaned into two columns called Field and Value and it looks like this:
Field Value
ID 1
ColA 123
ColB ABC
ColC D1E
ID 2
ColA 456
ColB DEF
ColC G6H
.
.
.
How do I convert this data into something like:
ID ColA ColB ColC
1 123 ABC D1E
2 456 DEF G6H
I've tried proc transpose, but it will just transpose all the columns as separate ones.
data have;
input Field $ Value $;
cards;
ID 1
ColA 123
ColB ABC
ColC D1E
ID 2
ColA 456
ColB DEF
ColC G6H
;;;;
run;
data addID;
set have;
retain row;
if field='ID' then row=Value;
run;
proc transpose data=addID out=want ;
by row;
id field;
var value;
run;
proc print data=want;run;
data have;
input Field $ Value $;
cards;
ID 1
ColA 123
ColB ABC
ColC D1E
ID 2
ColA 456
ColB DEF
ColC G6H
;;;;
run;
data addID;
set have;
retain row;
if field='ID' then row=Value;
run;
proc transpose data=addID out=want ;
by row;
id field;
var value;
run;
proc print data=want;run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.