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
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
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!
CALL SYMPUTX().
Maybe this then?
data _null_;
retain VAR1 'AAA' VAR3 'CCC';
call symputx(VAR1, VAR3);
call execute('%put &='||VAR1);
run;
AAA=CCC
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 save with the early bird rate—just $795!
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.