Hi,
I am executing a macro inside a data step and passing the data step variable to the macro.
But only last record variable is passed all the time (like my loop executed 2 times and 2 times last record variable only passed as a parameter).
The output should be
APPDIRECT_PROD_2018011001.dat|20180110|20180110|0000000001|APPDIRECT_PROD_2018011002.|ctl
APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl
But I am getting
APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl
APPDIRECT_PROD_2018011002.dat|20180110|20180110|0000000002|APPDIRECT_PROD_2018011002.|ctl
Where exactly the issue?
Thanks,
Swathi
Don't hand the name of a data step variable to call execute, but it's values:
x = cats('%nrstr(%b('!!trim(id)!!'))');
You are repeatedly creating macro variable new with call symput.
You are pushing macro calls onto the execution stack that contain the macro variable name, not it's value.
Since the macros won't execute before the data step has finished, all macro calls will use the last value put into macro variable new.
Instead of setting macro variables, use data step values in the call execute.
Thank you Sir,for your reply.
I changed the code to the variable directly,instead of the macro variable as i don't want to hardcode the valueas below.
x = cats( '%nrstr(%b(id))' ) ;
then the output is as below.
1 + %b(id)
id
2 + %b(id)
id
instead of the resolved variable value.
Is there any approach to achieve this?
Thanks!!
Don't hand the name of a data step variable to call execute, but it's values:
x = cats('%nrstr(%b('!!trim(id)!!'))');
Thank you sir!!
So let's eliminate the complexity of your data step from this problem and concentrate on just the CALL EXECUTE issue.
So first create your dataset and then use a DATA _NULL_ step to generate the macro calls.
%macro a ;
data FILELIST ;
....
output;
....
run;
data _null_;
set FILELIST;
call execute(cats('%nrstr(%b)(',id,')'));
run;
%mend a;
Now you can also probably make your data step much simpler (why are you calling CATT() function on string literals?), but perhaps you can leave that for another question.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.