Hi,
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?
This works:
%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:
%rowToMacroVariable(ab,impress,var_&brand);
There is no macro variable in the code you have provided for var_&brand. It does not exist hence the error. Perhaps you meant;
%rowToMacroVariable(ab,impress,var_&brand1.);
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.
Thanks RW9.
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 brand1=b
%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 ?
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.
Actually when you are calling the macro
%rowToMacroVariable(ab,impress,var_&brand);
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
%rowToMacroVariable(ab,brand,brand);
that why you will be getting error in the log because no macro varibale is present with name- brand
Hi Rohit,
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.
Hello,
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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.