DATA Step, Macro, Functions and more

Odd macro error

Reply
New Contributor
Posts: 2

Odd macro error

I'm running a fairly simple macro to import multiple sheets from an excel file into SAS. The problem is that in the DATA STEP the datafile ends up with a reverse slash, so that the DATAFiLE line reads:

DATAFILE= "O:\PROJ_LIB\Insurance\Schedule D Part34/2007_2009 Life SchDpt3.xls"

%MACRO LIFE1;

     %DO i = 1 %to 6;

    PROC IMPORT OUT=schd.LIFE_SchDpt4_2007_2009sheet&i.

           DATAFILE= "O:\PROJ_LIB\Insurance\Schedule D Part34\2007_2009 Life SchDpt3.xls"

            DBMS=XLS REPLACE;

            sheet="Sheet&i.";

            GETNAMES=YES;

RUN;

     %END;

    %MEND;

    %LIFE1;

Does anyone have any idea why I keep getting a forward slash instead of the backslash that I put into my code?

Thanks,

Andy

PROC Star
Posts: 7,363

Odd macro error

I've never encountered that behavior before but, regardless, it should still work correctly.  Does it?

New Contributor
Posts: 2

Re: Odd macro error

No, I get a SAS error similar to this:

Requested Sheet Name not found on Excel -> C:\Users\g1axp03\Documents\My SAS Files\My SAS

Files/2000_2010LifeSchDpt5.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           8.31 seconds

      cpu time            4.91 seconds

SAS can't recognize the file, because the forward slash is not in the filename.

I've tried some basic troubleshooting. Resetting SAS, changing the file location and changing the file name.

PROC Star
Posts: 7,363

Odd macro error

I have always found that SAS ignores the directionality of the slashes (i.e., works well regardless if one uses back slashes, forward slashes, or a combination of them).

However, in your example the input file was on drive O:, but you indicate that it returned a message regarding drive c: .. and in a typical user path rather than the path you had specified.

Could it be that it simply can't find the file in the path that you specified?

Ask a Question
Discussion stats
  • 3 replies
  • 432 views
  • 0 likes
  • 2 in conversation