03-10-2017 05:17 AM
I want to create some macro variable with the help of another macro variable. Please suggest how i can resolve below code?
I am in some sort of programming where i can just edit this macro only. So kindly dont suggest to create another macro. I can only edit this one.
%macro rowToMacroVariable(dataSetName,variableName,macroVariableName); data _null_; set &dataSetName; call symputx("¯oVariableName"||strip(put(_n_,best.)),&variableName,"G"); run; %mend; data ab; input brand$ impress$; cards; b TJ c DJ d PJ ; run; %rowToMacroVariable(ab,brand,brand); %rowToMacroVariable(ab,impress,var_&brand); %put _GLOBAL_;
Now with the help of above code i want to create
brand1=b brand2=c brand3=d which is working perfectly fine. But in next row when i am trying to create var_b=TJ var_c=DJ var_d=PJ it throws an error. I am not sure why this is hapenning?
03-10-2017 05:54 AM
%macro rowToMacroVariable(dataSetName,variableName,macroVariableName); data _null_; set &dataSetName; call symputx("¯oVariableName"||strip(put(_n_,best.)),%trim(&variableName),"G"); run; %mend; data ab; input brand$ impress$; cards; b TJ c DJ d PJ ; run; %rowToMacroVariable(ab,brand,brand); %put _GLOBAL_;
And creates the three macro variables. This line however:
There is no macro variable in the code you have provided for var_&brand. It does not exist hence the error. Perhaps you meant;
I would again take this opportunity to state that this code is not the way to proceed. You are far overcomplicating your problems and leading to much more serious problems down the line.
03-10-2017 06:09 AM
Actully issue is with
Because Here i cannot use &brand1 or 2 because its not in loop. I dont want to run loop because my func will again open whole dataset and create various unwanted variables. So I will explain once more my problem statment is :
I have 100's of rows in data set. But some how programing is already done with the help of this 100's of macro variable. So currenty we are using like
%let brand2=c and so on.
So my motive was to remove this code and for this i have created a dataset. Now Call Symputx works very well fine if i am using static variable name that is "brand". But now i want to combine this "brand1" with some other text to create another variable.
i want to pass var_&brand and i want it will create var_b. I donnot want to make it in loop. So is there any way ? or can you suggest what is the best way for this problem statment ?
03-10-2017 06:16 AM
So your going to create hundreds of macro variables and then hundreds more with a slightly different name, to run several macros.
I am sorry, you are lost to madness. Base SAS is a programming language deisnged to process datasets there are lots of functions, data modelling techniques, and processes deisgned for making data processing simple and easily maintainable. You are ignoring this in total and remaking the whole thing in macro language, hence I can't help any further.
03-10-2017 06:21 AM
03-10-2017 06:06 AM
Actually when you are calling the macro
Yor are givng &brand when calling the macro .there is no macro variable present with the name Brand
there are macro variable present but they have different names brand1,brand2 and brand =3 which are created when you have run below line
that why you will be getting error in the log because no macro varibale is present with name- brand
03-10-2017 06:13 AM
Agreed this is because &brand is not resolved, but i want to know how i can relove it in Call symput because it is creating below error. Can you have some look in snapshot attached.
03-10-2017 06:54 AM
If your goal is only to generate var_<brand> macrovariables, you can do it directly.
data _NULL_; set ab; call symput(cats("var_",brand),impress); run;