10-04-2013 02:44 PM
I was wondering if there is a way to write dataset variable into a macro variable and use the macro variable within the same datastep.
I have tried different approaches to do the following; but have been running into call symput, excute so far. Thanks for any help that might help to solve the situation...
input anID surfix $;
input anID A_2_1 A_2_2 A_2_3 B_2_1 B_2_2 B_2_3;
1 0.1 0.2 0.3 0.4 0.5 0.6
2 1.1 1.2 1.3 1.4 1.5 1.6
3 2.1 2.2 2.3 2.4 2.5 2.6
%let prefixlist=A B;
Merge atmp atmpdt; by anID;
/*Intention: read current row variable surfix into the macro variable asurfix*/
nbvar = countw("&prefixlist"," ");
/*Intention: for each name in the macro variable "prefixlist"
create a dataset set variable initiliazed with the value in the var &aprefix._&Asurfix */
do count = 1 to nbvar;
call symput('aprefix',scan("&prefixlist",count," "));
10-04-2013 02:58 PM
To tell you the truth, I wouldn't do this with macros at all, I would use PROC TRANSPOSE.
proc transpose data=atmpdt out=a;
merge a atmp;
Now you can assign A and B to the proper variables by matching text strings in data set AA, and throw out the observations in aa that don't match;
10-06-2013 09:52 PM
SAS variables get created during the compilation phase of a data step. It is not possible to create additional SAS variables during execution phase.