BookmarkSubscribeRSS Feed
markc
Obsidian | Level 7


Hello,

 

How do I assign values to the values within macro variables which I want to be variables in turn?

 

For example, let's say I assign a number of question codes:

 

data question_vars;
 input question_code $25.;
 datalines;
QUESTION_CODE001

QUESTION_CODE002

QUESTION_CODE003
run;

 

proc sql noprint;
    select question_code into: questioncodelist separated by ' '
    from question_vars;
quit;

 

So, from here, how do I assign a value to QUESTION_CODE001?  In other words, I want to make the values within question_code  be variables unto which I can assign values to.

 

Kind regards,

Mark

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Like this?

data question_vars;
 input question_code $25.;
 datalines;
QUESTION_CODE001
QUESTION_CODE002
QUESTION_CODE003
run;

proc sql noprint;
  select catt('&',question_code) into: questioncodelist separated by ' '
  from question_vars;
quit;

%let question_code001=a;
%let question_code002=b;
%let question_code003=c;

%put &=questioncodelist;

QUESTIONCODELIST=a b c

markc
Obsidian | Level 7

Thank you very much for your reply!

 

I'm finding this one hard to put into words to be honest.

 

Basically I would like to be able to read through a dataset and I would like to make the value of a variable, in turn be another variable which I can assign another value to.

 

For example let's say an observation contains:

Columns:             var1  var2  var3

Row 1 contents:  AAA  BBB  CCC

 

So as I am reading through var1, I would like to be able to make its value i.e. AAA in turn be a variable name to which I can assign var3.

 

In other words:

let the value of (var1) = the value of var3

 

so that new variable AAA = CCC.

 

Many thanks!

 

 

 

ChrisNZ
Tourmaline | Level 20

Maybe this then?

data _null_;
  retain VAR1 'AAA'  VAR3 'CCC';
  call symputx(VAR1, VAR3);
  call execute('%put &='||VAR1);
run;

AAA=CCC

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 786 views
  • 4 likes
  • 3 in conversation