Hello, I am trying to PROC IMPORT several files in a loop. Some of the files have the name SP15_[Year] and others have SP15_[Year]_[Year+1]. Seems like I should be able to use %DO %WHILE for this because there exists a constant, c such that for [Year] > c, the files have two years in the name. In my %DO %WHILE loop I keep getting errors related to quoted strings. But I can use CTRL+F to verify that all quotations are closed. If I take one of the PROC IMPORT commands out of the loop and simply force the loop index to take a particular value, I get the 'ERROR: Macro keyword LET appears as text' message. The result I want is a set of SAS datasets named the following (i.e. the SAS dataset name can/should be the same as the imported file name): SP15_2017 SP15_2018 SP15_2019_2020 SP15_2021_2022 SP15_2023_2024 SP15_2025_2026 SP15_2027_2028 SP15_2029_2030 My simplified attempt is: ***************************** %let i = 2017; proc import datafile= "&path/SP15_&i" out=SP15_&i dbms=xlsx replace; RANGE="Sheet 1$.A1:I8761"; GETNAMES=YES; run; (This returns the ERROR in the subject) ***************************** My %DO %WHILE loop is: ***************************** %macro extract(startyear, endyear); %do i = &startyear %to &endyear; %do %while(&i in (2017, 2018)); proc import datafile= "&path/SP15_&i" out=SP15_&i dbms=xlsx replace; RANGE="Sheet 1$.A1:I8761"; GETNAMES=YES; run; %end; %do %while(&i in (2019, 2020)); proc import datafile= "&path/SP15_2019_2020" out=SP15_2019_2020 dbms=xlsx replace; RANGE="Sheet 1$.A1:I8761"; GETNAMES=YES; run; %end; %do %while(&i in (2020, 2028)); %let k = %eval(&i +1); %let j = %eval(&k + 1); proc import datafile= "&path/SP15_&k_&j" out=SP15_&k_&j dbms=xlsx replace; RANGE="Sheet 1$.A1:I8761"; GETNAMES=YES; run; %end; %do %while(&i = 2029); proc import datafile= "&path/SP15_2029_2030" out=SP15_2029_2030 dbms=xlsx replace; RANGE="Sheet 1$.A1:I8761"; GETNAMES=YES; run; %end; %end; %mend; %extract(2017, 2030); (This returns "The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space between a quoted string and the succceeding identifier is recommended." This error is returned at the top and the bottom of the log. The bottom of the log also returns "The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation marks.") Thanks for your suggestions. -S
... View more