2
votes

I need to import the same excel file into SAS every week, and filenames have different dates like below: file_01012021.xls file_01072021.xls

When I set up macro variables I'm getting an error due to the " ' " in the MMDDYYYY macro variable

%let MMDDYYY = '01012021'; /*Update each week*/
%let extension '.xls';
%let file = 'File_'
%let filename = &file||put(&MMDDYYYY,8.)||&extension;

proc import
    out = dataset1
    datafile = "/workspace/&filename"  
    dbms = xls replace;
run;

Are there ways to get this to work?

1
Why did you put the single quotes into the values of the macro variables if they are just going to cause you problems?Tom
It's helpful to think of macro variables resolving as literal text replacement. So the quotes are added to your variable creating a mess. All macro variables are stored as 'text' so no need to include quotes.Reeza

1 Answers

4
votes

You do not need quotes in a macro variable assignment statement, and you do not need to concatenate them with a data step concatenation statement. Simply put them together by resolving each macro variable.

%let mmddyy = 01012021;
%let extension = .xls;
%let file = File_;
%let filename = &file.&mmddyy.&extension;