Error when using a macro variable in a PROC IMPORT

  • Follow


Hi,

I am at a loss as to why my macro variable DATA_FOLDER does not work
with my proc import. I have tried various combinations using a " and a
' defining the variable and in the proc import but any combination I
seem to use does not work. Here I am using single quotes defining the
macro variable and no quotes around the usage of the variable.

6721  %macro test;
6722  %let data_folder = 'c:\';
6723  libname test &data_folder.;
6724  proc import
6725  datafile = &data_folder.'test.xls'
6726  out = test.test1 dbms=excel replace;
6727  run;
6728  %mend test;
6729  %test;
MPRINT(TEST):   libname test 'c:\';
NOTE: Libname TEST refers to the same physical library as ACR.
NOTE: Libref TEST was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\
MPRINT(TEST):   proc import datafile = 'c:\''test.xls' out =
test.test1 dbms=excel replace;
MPRINT(TEST):   AEXC;
MPRINT(TEST):   run;

ERROR: Unable to import, file c:\'test.xls does not exist.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds

0
Reply SAS 3/1/2010 1:03:09 PM

I don't see why you'd wrap your code in a macro, but I'd think the
following accomplishes what you want:

%macro test;
%let data_folder = c:\;
libname test "&data_folder.";
proc import
datafile = "&data_folder.test.xls"
out = test.test1 dbms=excel replace;
run;
%mend test;
%test

HTH,
Art
--------
On Mar 1, 8:03 am, SAS User <sasuser2...@googlemail.com> wrote:
> Hi,
>
> I am at a loss as to why my macro variable DATA_FOLDER does not work
> with my proc import. I have tried various combinations using a " and a
> ' defining the variable and in the proc import but any combination I
> seem to use does not work. Here I am using single quotes defining the
> macro variable and no quotes around the usage of the variable.
>
> 6721  %macro test;
> 6722  %let data_folder = 'c:\';
> 6723  libname test &data_folder.;
> 6724  proc import
> 6725  datafile = &data_folder.'test.xls'
> 6726  out = test.test1 dbms=excel replace;
> 6727  run;
> 6728  %mend test;
> 6729  %test;
> MPRINT(TEST):   libname test 'c:\';
> NOTE: Libname TEST refers to the same physical library as ACR.
> NOTE: Libref TEST was successfully assigned as follows:
>       Engine:        V9
>       Physical Name: c:\
> MPRINT(TEST):   proc import datafile = 'c:\''test.xls' out =
> test.test1 dbms=excel replace;
> MPRINT(TEST):   AEXC;
> MPRINT(TEST):   run;
>
> ERROR: Unable to import, file c:\'test.xls does not exist.
> NOTE: The SAS System stopped processing this step because of errors.
> NOTE: PROCEDURE IMPORT used (Total process time):
>       real time           0.04 seconds
>       cpu time            0.03 seconds
0
Reply art297 (4237) 3/1/2010 3:45:04 PM


On Mar 1, 2:03=A0pm, SAS User <sasuser2...@googlemail.com> wrote:
> Hi,
>
> I am at a loss as to why my macro variable DATA_FOLDER does not work
> with my proc import. I have tried various combinations using a " and a
> ' defining the variable and in the proc import but any combination I
> seem to use does not work. Here I am using single quotes defining the
> macro variable and no quotes around the usage of the variable.
>
> 6721 =A0%macro test;
> 6722 =A0%let data_folder =3D 'c:\';
> 6723 =A0libname test &data_folder.;
> 6724 =A0proc import
> 6725 =A0datafile =3D &data_folder.'test.xls'
> 6726 =A0out =3D test.test1 dbms=3Dexcel replace;
> 6727 =A0run;
> 6728 =A0%mend test;
> 6729 =A0%test;
> MPRINT(TEST): =A0 libname test 'c:\';
> NOTE: Libname TEST refers to the same physical library as ACR.
> NOTE: Libref TEST was successfully assigned as follows:
> =A0 =A0 =A0 Engine: =A0 =A0 =A0 =A0V9
> =A0 =A0 =A0 Physical Name: c:\
> MPRINT(TEST): =A0 proc import datafile =3D 'c:\''test.xls' out =3D
> test.test1 dbms=3Dexcel replace;
> MPRINT(TEST): =A0 AEXC;
> MPRINT(TEST): =A0 run;
>
> ERROR: Unable to import, file c:\'test.xls does not exist.
> NOTE: The SAS System stopped processing this step because of errors.
> NOTE: PROCEDURE IMPORT used (Total process time):
> =A0 =A0 =A0 real time =A0 =A0 =A0 =A0 =A0 0.04 seconds
> =A0 =A0 =A0 cpu time =A0 =A0 =A0 =A0 =A0 =A00.03 seconds

Hi SAS User,

You can actually see the problem pretty well in the log you posted:
MPRINT(TEST):   proc import datafile =3D 'c:\''test.xls' out =3D
test.test1 dbms=3Dexcel replace;

Look at the path after 'datafile'. The quotations are wrong. Try this:
%macro test;
  %let data_folder =3D c:\;                    %* removed single
quotes ;
  libname test "&data_folder.";              %* added double quotes
(double, because otherwise your macro variable would not be resolved);
  proc import
       datafile =3D "&data_folder.test.xls"    %* removed single and
added double quotes ;
       out =3D test.test1 dbms=3Dexcel replace;
  run;
%mend test;
%test;

HTH,
Alex
0
Reply Alex 3/1/2010 4:03:06 PM

the problem is the ' in the variable &data_folder.

Try to use something like:

%let data_folder=%str(c:\);
libname test "&data_folder";
....
datafile="&data_folder.test.xls";
....

Gerhard




On Mon, 1 Mar 2010 05:03:09 -0800, SAS User <sasuser2010@GOOGLEMAIL.COM>
wrote:

>Hi,
>
>I am at a loss as to why my macro variable DATA_FOLDER does not work
>with my proc import. I have tried various combinations using a " and a
>' defining the variable and in the proc import but any combination I
>seem to use does not work. Here I am using single quotes defining the
>macro variable and no quotes around the usage of the variable.
>
>6721  %macro test;
>6722  %let data_folder = 'c:\';
>6723  libname test &data_folder.;
>6724  proc import
>6725  datafile = &data_folder.'test.xls'
>6726  out = test.test1 dbms=excel replace;
>6727  run;
>6728  %mend test;
>6729  %test;
>MPRINT(TEST):   libname test 'c:\';
>NOTE: Libname TEST refers to the same physical library as ACR.
>NOTE: Libref TEST was successfully assigned as follows:
>      Engine:        V9
>      Physical Name: c:\
>MPRINT(TEST):   proc import datafile = 'c:\''test.xls' out =
>test.test1 dbms=excel replace;
>MPRINT(TEST):   AEXC;
>MPRINT(TEST):   run;
>
>ERROR: Unable to import, file c:\'test.xls does not exist.
>NOTE: The SAS System stopped processing this step because of errors.
>NOTE: PROCEDURE IMPORT used (Total process time):
>      real time           0.04 seconds
>      cpu time            0.03 seconds
0
Reply gerhard.hellriegel (2531) 3/1/2010 7:21:06 PM

3 Replies
186 Views

(page loaded in 0.07 seconds)

Similiar Articles:













7/15/2012 12:26:59 AM


Reply: