Hello
What is the way to create wanted data set from have data set?
This is transpose of one row (wide) into long with putting var labels into one column in the desired data set
Data have;
label X1='abc' X2='frg' X3='Per' X4='Tim' X5='Loc';
input X1 X2 X3 X4 X5;
cards;
100 200 50 300 180
;
Run;
Data wanted;
input field_name $ field_label $ value;
cards;
X1 abc 100
X2 frg 200
X3 per 50
X4 Tim 300
X5 Loc 180
;
Run;
Try this
data want;
set have;
array x x:;
do over x;
field_name = vname(x);
field_label = vlabel(x);
value = x;
output;
end;
keep field_name field_label value;
run;
Result:
field_name field_label value X1 abc 100 X2 frg 200 X3 Per 50 X4 Tim 300 X5 Loc 180
Proc transpose can do this:
proc transpose data=have out=want(rename=(col1 = value)) label=field_label name=field_name;
var x1-x5;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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.