2

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?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
crlaoy
  • 99
  • 7
  • Why did you put the single quotes into the values of the macro variables if they are just going to cause you problems? – Tom Jan 15 '21 at 22:42
  • 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 Jan 18 '21 at 03:54

1 Answers1

4

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;
Stu Sztukowski
  • 10,597
  • 1
  • 12
  • 21