BookmarkSubscribeRSS Feed
esvenson
Fluorite | Level 6

Hello Forum,

I'm trying to create a macro that will import 12 months worth of data from 12 separate files.  I receive error messages that symbolic reference MTH01 and MON01 cannot resolve.  I also receive an error 22-322: syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG, FILE, OUT....etc.  I thought that a macro previously defined in a program could later be invoked within a macro?

 

Can someone please tell me what I'm doing wrong or what I can do to correct this?  Thank you very much in advance.

~ Eric

 

rsubmit;

%let MTH01=%sysfunc(dequote("'%sysfunc(intnx(MONTH,%sysfunc(today()),-1),monyy7.)'"));

%let MON01=%sysfunc(dequote("'%sysfunc(intnx(MONTH,%sysfunc(today()),-1),mmyyn6.)'"));

endrsubmit;

 

%macro import(MONYY=,MMYY=);

PROC IMPORT OUT=tpt_lvt_his_&MMYY.

DATAFILE= "\\xxxxxxx\xxxxxxx\xxxxx\xxxx\xxxxx\xxxx\&MONYY.\TPT_ora_apples_&MMYY. (from zzz Sharepoint).xls"

DBMS=EXCEL REPLACE;

GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES;

RUN;

 

%mend;

%import (MONYY=&MTH01.,MMYY=&MON01.);

 

1 REPLY 1
Reeza
Super User

Is your endrsubmit early?

 

You need to compile the macro and macro variables in the same location - both locally or both on the server.

 

Your macro variable can't have quotes though, otherwise the code generated is:

 

 

MMYY resolves to -> '102016'

PROC IMPORT OUT=tpt_lvt_his_&MMYY. becomes

PROC IMPORT OUT=tpt_lvt_his_'102016'

 

This isn't valid SAS sytnax.

The code becomes simpler though:

 

%let MON01=%sysfunc(intnx(MONTH,%sysfunc(today()),-1),mmyyn6.);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1285 views
  • 0 likes
  • 2 in conversation