BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rmlmrmlm
Obsidian | Level 7
Hello.

I have a dataset with only one variable and 50 observations. The variable contains names of other I want to use to create a new dataset. Of course, these names change, depending on the steps of the processing.

Example of the dataset_1:

variable_name
--------------------
brand
colour
year
maxspeed


The new dataset to create, dynamicaly and empty, must have the following variables:

Example of dataset_2:

brand colour year maxspeed
------------------------------------------------

This is some kind of transpose. I tried some transposes but it didn't work out.

Can someone help?
Thanks a lot.
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

data have;
input name : $20.;
cards;
brand
colour
year
maxspeed
;
run;
proc transpose data=have out=want;
id name;
run;

View solution in original post

11 REPLIES 11
rmlmrmlm
Obsidian | Level 7
Important: It's not possible to use the select variable into :var separated by ' ' because sometime we have so many columns that concatenated it exceeds the max lengrh of a macro variable.
rmlmrmlm
Obsidian | Level 7
Yes, you are right! I didn' think about it. SAS rookie.
rmlmrmlm
Obsidian | Level 7
Well ... I was checking ... In real life, the variables are all numeric.

Can I use a kind of transpose, @Kurt_Bremser?
Reeza
Super User

You only have one column? What would be in the variables created, missing? A full example would be helpful. 

PGStats
Opal | Level 21

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;
PG
Astounding
PROC Star

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.

Shmuel
Garnet | Level 18

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;

    

Ksharp
Super User

data have;
input name : $20.;
cards;
brand
colour
year
maxspeed
;
run;
proc transpose data=have out=want;
id name;
run;

rmlmrmlm
Obsidian | Level 7
For my needs, this answer is valid.
Thanks.
gk6565
Calcite | Level 5

Thanks for this useful answer.

 

It's working.! Kudos to you.

SAS Innovate 2025: Register Now

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!

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
  • 11 replies
  • 4724 views
  • 13 likes
  • 8 in conversation