02-03-2012 08:07 PM
It will be great if somebody could help me out here. I am trying to create this new variable from my existing dataset. In my current dataset I have variables section1 and section2 and other variables var1_1, var_3, var1_4, etc based on the value of the variables section1 and section2. I am trying to create 2 new variables that contain the value of variables var_i, var_j where "i" and "j" are the values of variables section1 and section2.
I don't fully understand how symput works but have the following working code. Somehow hist1 and hist2 only show the value of the corresponding var_k for the very last record in the dataset. And also, how do I convert the macro variable to a variable in the dataset "sections_mod"?
set sections end=eof;
if eof then do;
call symput("num1", trim(compress(Section1))); call symput('Hist1', VAR_&num1); hist1= &Hist1;
call symput("num2", trim(compress(Section2))); call symput('Hist2', VAR_&num2); hist2= &Hist2;
02-03-2012 08:38 PM
I don't have answer for your specific question, which requires more information on your data set. Generally speaking, you don't need to create a data set variable from another data set variable using macro variable as a middle man. What 's wrong with just using assignment statement (or plus whatever operators needed) to do the job (new=old)? In theory, you sure can use call symput to first retrieve values into macro variables and then using symget to put the value back into your data set variables, well, for your scenario, doing that is like traveling from DC to NY via north pole.
just my 2 cents,
02-03-2012 08:47 PM
Not sure what macro variables have to do with your problem?
If you have a variable, call it NAME, that contains the name of another variable, call it X, and you want to get the value of the variable X there are a few ways.
If your variables names and data are like your example use an array;
array v var1 - var10;
want = v(section1);
Otherwise you might look at the VVALUEX function.
want = vvaluex(name);