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;
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.