BookmarkSubscribeRSS Feed
hellind
Quartz | Level 8

 

I am using SAS EG 8.3

 

I use File --> Import Data to import a few files to the SAS server.

 

Every new month, I have to Right Click the file and update the File Location.

 

Is there a way to parameterize the file location, so that all I just need to update from yymm=202304 to yymm = 202305 in a macro variable and the Import Data Wizard will pick up the new files?

IMPORTDATAFILELOCATION.PNG

 

2 REPLIES 2
Kurt_Bremser
Super User

Instead of the Import Wizard, use the Copy Files task (where you can use macro variables), and a subsequent code node to read the file after it has been copied to the SAS server.

José_Costa_biw
Fluorite | Level 6

Hi,

 

Supposing that the structure of the files being imported remains constant throughout the months and years, one way to do that is the following:

 

First, make sure that you selected the last option in the fourth step of the import object (you can "Modify task", select the option, and run to get the code):

 

Jos_Costa_biw_0-1688558875027.png

 

That code will make reference to the file you're importing:

 

Jos_Costa_biw_1-1688559026252.png

 

Now, copy all the code of the import to a new program, add a %LET statement at the top to create the macro variable that will establish the yearmonth to run (i called it YEARMONTH, name it as you like):

 

Jos_Costa_biw_2-1688559230724.png

 

... and now you can replace with the new macro variable reference where needed (i don't know if the SAS table you're creating also contains the yearmonth, if it does, don't forget to replace there too), and run the program:

 

Jos_Costa_biw_3-1688559297836.png

 

Two very important things here:

  • When you reference a macro variable inside a string, the string must be delimited by double quotes ("), not single quotes ('). Double quotes will allow for macro variable resolve inside them, single macro quotes won't.
  • If you need to reference a macro variable inside a string and right before a period (.), as in this example, follow the macro variable reference with an additional period.
    Notice that, in the last image, i have "TABLE&YEARMONTH..csv".
    The first period will be interpreted as a delimiter for the macro variable name and be "consumed", while the second period will be interpreted literally as a period.

Hope this helps!

 

Best regards,

José Costa

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 307 views
  • 0 likes
  • 3 in conversation