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.
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.