BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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 
andreas_lds
Jade | Level 19

Proc transpose can do this:

proc transpose data=have out=want(rename=(col1 = value)) label=field_label name=field_name;
   var x1-x5;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 864 views
  • 4 likes
  • 3 in conversation