data have;
input name : $20.;
cards;
brand
colour
year
maxspeed
;
run;
proc transpose data=have out=want;
id name;
run;
You need more information in your first dataset, not just names: variable type, length, formats, ...
You only have one column? What would be in the variables created, missing? A full example would be helpful.
You can also use a temporary file:
filename toto temp;
data _null_;
set have;
file toto;
put variable_name "=0;";
run;
data have;
%include toto;
stop;
run;
Here's a transpose approach:
data have2;
set have;
num_var = 1;
run;
proc transpose data=have2 out=want1 (drop=_name_ _label_);
var num_var;
id variable_name;
run;
data want2;
set want1;
stop;
run;
The transpose creates all the numeric variables with a value of 1. The final DATA step removes that observation, but leaves the variable definitions in place.
You can do it in one step, assumed all variables are numeric:
data _NULL_;
infile datalines truncover;
input vname $;
if _N_ = 1 then call exceute('data test; length ');
if vname ne '===' /* input data assigned to end of input */
then call execeute('strip(vname) || ' ');
else call excecute(' 8; delete; run;');
datalines;
brand
colour
year
maxspeed
===
; run;
run;
data have;
input name : $20.;
cards;
brand
colour
year
maxspeed
;
run;
proc transpose data=have out=want;
id name;
run;
Thanks for this useful answer.
It's working.! Kudos to you.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.