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

When I pass a file value as file path and file in a macro, why I continue to hit errors with an extra slash '/' in front of the file name: 

 

%LET fn="/dir/folder/filename.xls";

 

%ImportDataSheet(df=&fn.);

 

The Macro code

 

"proc import datafile=&df dbms=xls out=resulename replace;" 

 

got a "Can not load sas log" error, with the below file path/name showing:

 

/dir/folder//filename.xls

 

The program inserted an extra '/' in front of the file name, preventing successful loading of the file.

 

How do I successfully pass file path/name variables?

 

Appreciate your help on this very much!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@zz wrote:

 

Requested Sheet Name not found on Excel -> /dir/folder/data//datafile.xls
Requested Input File Is Invalid
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

 


 

Check your excel file and ensure it has a sheet labeled DT without any extra spaces.

I would also suggest just running that code, without the macro portion until you get it working and then switch to the macro code.

View solution in original post

4 REPLIES 4
Reeza
Super User

Although that may appear to be the error, it's not. There's something else inyour code.

 

Please post your full code and log, using the code icon above, rather than plain text in the window. 

The full code/log should provide enough info to help find the error.

zz
Calcite | Level 5 zz
Calcite | Level 5

Thank you, Reeza!  Here is the code and log:

 

%MACRO ImportDataSheet( df= );
    proc import datafile=&df dbms=xls out=subjects_nmi replace;
    sheet='dt';
    getnames=yes;
    run;
%MEND ImportDataSheet;

 

%let dpf = "/dir/folder/data/datafile.xls";

%PUT dpf=&dpf.;

%ImportDataSheet( df = &dpf. );

 

********************

9 %MACRO ImportDataSheet( df= );
10 proc import datafile=&df dbms=xls out=subjects_nmi replace;
11 sheet='dt';
12 getnames=yes;
13 run;
14 %MEND ImportDataSheet;
15
16 %let dpf = "/dir/folder/data/datafile.xls";
17
18 %PUT dpf=&dpf.;
dpf="/dir/folder/data/datafile.xls"
19
20 %ImportDataSheet( df = &dpf. );

Requested Sheet Name not found on Excel -> /dir/folder/data//datafile.xls
Requested Input File Is Invalid
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

 

Reeza
Super User

@zz wrote:

 

Requested Sheet Name not found on Excel -> /dir/folder/data//datafile.xls
Requested Input File Is Invalid
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

 


 

Check your excel file and ensure it has a sheet labeled DT without any extra spaces.

I would also suggest just running that code, without the macro portion until you get it working and then switch to the macro code.

ballardw
Super User

Also the path you are passing is relative and will expecte the file mentioned to be in a folder subordinate to the current active path SAS is using. Which may very well not be where you expect. I would recommend always using a complete path to insure the location.

 

Also, are you running in a server environment? The input file would have to be on the server to be found.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 4650 views
  • 1 like
  • 3 in conversation