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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1 reply
  • 802 views
  • 0 likes
  • 2 in conversation