Can you include macro in SAS proc import filename?

Viewed 345

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 Answers

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;
Related