BookmarkSubscribeRSS Feed
Lakshmisas
Calcite | Level 5

 

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;

4 REPLIES 4
Tom
Super User Tom
Super User

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().

Lakshmisas
Calcite | Level 5
Hi ,

Thanks for your prompt response .

Issue got fixed by placing comma between args1 and args2.

call execute(cats('%nrstr(%SasDS(',args1,',',args2,'));'));
mkeintz
PROC Star

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.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kurt_Bremser
Super User

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,'));'));

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1201 views
  • 0 likes
  • 4 in conversation