BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
marathoner
Fluorite | Level 6

I have an excel file report name Reference_Report. The file name ends with a time stamp every time it is exported to my machine.
My library reference the report in my desktop. Instead of updating the file name, I thought I would use a wild card. When I run the code SAS gives me ERROR: Physical file does not exist, C:\WINDOWS\system32\FILENAME.xlsx

What am I doing wrong?

libname Ref 'C:\Users\1\Desktop\';

%let location = 'C:\Users\1\Desktop\'; 
%let file = 'Reference_Report';
%let extension ='.xlsx';
%let filename = &location&file*&extension;

proc import 
datafile = filename
out = Ref.Report1
dbms = xlsx
replace;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First thing you did not reference your "filename" macro variable.Should look like:

proc import 
datafile = &filename.
out = Ref.Report1
dbms = xlsx
replace;
run;

 

Second your "filename" will be built incorrectly. By placing quote characters in the Location,File and Extension variables your Filename is: 'C:\Users\1\Desktop\''Reference_Report'*'.xlsx'

Which has two single quotes in the middle and other extra quotes. If you want to generate 'C:\Users\1\Desktop\Reference_Report*.xlsx'

You need different code.

%let location = C:\Users\1\Desktop\; 
%let file = Reference_Report;
%let extension =.xlsx;
%let filename = "&location.&file.*&extension.";
 %put &filename.;

Double quotes are used so the macro variables will resolve inside them.

But if you have more than one of the "reference_report.xlsx" files in that folder proc import will choke on that as it doesn't deal with multiple input files.

View solution in original post

2 REPLIES 2
Sajid01
Meteorite | Level 14

Hello 
Please remove the single quotes from macro definitions. Have them as shown below.

Macro variable includes everything from the equal to sign and semi colon.

%let location = C:\Users\1\Desktop\; 
%let file = Reference_Report;
%let extension =.xlsx;
%let filename = &location&file&extension;
%put &=filename;

 

ballardw
Super User

First thing you did not reference your "filename" macro variable.Should look like:

proc import 
datafile = &filename.
out = Ref.Report1
dbms = xlsx
replace;
run;

 

Second your "filename" will be built incorrectly. By placing quote characters in the Location,File and Extension variables your Filename is: 'C:\Users\1\Desktop\''Reference_Report'*'.xlsx'

Which has two single quotes in the middle and other extra quotes. If you want to generate 'C:\Users\1\Desktop\Reference_Report*.xlsx'

You need different code.

%let location = C:\Users\1\Desktop\; 
%let file = Reference_Report;
%let extension =.xlsx;
%let filename = "&location.&file.*&extension.";
 %put &filename.;

Double quotes are used so the macro variables will resolve inside them.

But if you have more than one of the "reference_report.xlsx" files in that folder proc import will choke on that as it doesn't deal with multiple input files.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 849 views
  • 1 like
  • 3 in conversation