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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 4 replies
  • 1545 views
  • 4 likes
  • 3 in conversation