Hi All,
Can anyone suggest me in executing a macro for each row in the dataset , passing arguments dynamically as given below.
Suggesting a solution to me is hifhly appreciated.
----------------------------------------------------------------
Read Data1 dataset with Columns "Company" and "DSName"
eg: Company DSName
Comp1 DS1
comp2 DS2
-------------------------------------------------------
data _null_;
set Work.Data1;
length args1 $300. args2 $100.;
args1 = cats("'C:\Test\",Company,".xlsx'");
args2 = cats(DSName,'_2018');
put "args1=" args1;
put "args2=" args2;
call execute(cats('%nrstr(%SasDS(',args1,args2,'));'));
run;
-------------------------------------------------------
%let Qtr=Q1;
%macro SasDS(Name,Dss);
libname Perm&&Qtr 'C:\Test\SasDS\&&Qtr';
PROC IMPORT OUT=Perm&&Qtr.&DSS.
DATAFILE=&Name.
DBMS=EXCEL REPLACE;
SHEET="&&Qtr";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
%mend SasDS;
Did it not work? What error did you get?
Make sure to compile the macro before running the data step that pushes calls to it onto the stack via CALL EXECUTE().
The call execute statements will cause the embedded commands to be executed, in sequence, immediately after the data step. Since the code to be executed includes use of the macro SASDS, that macro must be defined prior to the data step execution.
Perhaps, it's just the way you described your question, but it appears that you don't define the SASDS macro until after the data step.
If that's not the case, then as @Tom says, please show us what happened that you didn't expect.
Your macro expects two arguments separated by a comma, but your call execute does not supply that comma. Expand the call execute:
call execute(cats('%nrstr(%SasDS(',args1,',',args2,'));'));
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.