BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
carles
Fluorite | Level 6

Good Morning!, 

 

I know this question might be silly but I am trying to achieve the following: 

 

(1) I have a variable for instance: %let Var1 = A B C;

Then I want to pass it in a Dataset column such that

 

data want; 

WantedColumn = &Var1;

run; 

 

However, this does not work. I have tried several combinations with PUT and SCAN but havent found the good one. 

 How is it done ??

 

Thank you for your time !,

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Then do

 

%let Var1 = A B C;

data want(drop=i); 
    do i=1 to countw("&Var1");
        WantedColumn=scan("&Var1", i);
        output;
    end;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Put quotes around your macro variable

 

%let Var1 = A B C;

data want; 
    WantedColumn = "&Var1";
run; 
carles
Fluorite | Level 6

This outputs me everything in one place but i want :

 

WantedColumn

A

B

C

 

 

NOT

 

Wanted Column

A B C

 

PeterClemmensen
Tourmaline | Level 20

Then do

 

%let Var1 = A B C;

data want(drop=i); 
    do i=1 to countw("&Var1");
        WantedColumn=scan("&Var1", i);
        output;
    end;
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3 replies
  • 840 views
  • 0 likes
  • 2 in conversation