|
|
Error when using a macro variable in a PROC IMPORT
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: use macro to import multiple excel files? - comp.soft-sys.sas ...how can i use macro to import multiple excel ... SAS dataset with the four variables ... PROC IMPORT for multiple txt files - comp.soft-sys.sas use macro to import multiple excel ... proc import - how to define char or numeric as char - comp.soft ...when I use proc import, it can't input these variables properly. ... are my programs: %MACRO READ(DSN, Vars, Id, DSTrans); PROC IMPORT ... dbinfo.ch" #include "error.ch ... How to use macro variable in libname statatement. - comp.soft-sys ...... soft-sys.sas How to use macro variable in libname statatement. - comp.soft-sys ... Re: Error when using a macro variable in a PROC ... ... How to use macro variable in libname ... Macro not resoved - comp.soft-sys.sasIt Throws the Error as :Apparent symbolic reference ASAT not resolved. %macro labalat(file = ,out =); proc import ... How to use macro variable in libname ... PROC IMPORT for multiple txt files - comp.soft-sys.sas> > * Set up variables for the location of ... A0 =A0 =A0 =A0 =A0 =A0 put "ERROR ... PROC IMPORT for multiple txt files - comp.soft-sys.sas use macro to import multiple excel ... Macro error - comp.soft-sys.sas... text - > > > - Show quoted text - > > i am trying to this macro variable in proc gplot ... Macro Error - Excel - Office.com Show All Hide All The Macro Error message ... read and merge lots of txt files, macro? - comp.soft-sys.sas ...SAS macro variable - comp.soft-sys.sas That is easy in macro ... PROC IMPORT for multiple txt files - comp.soft-sys.sas use macro to ... Using Access to Combine Multiple Excel ... reading text files - comp.soft-sys.sasIs there a way in sas to put the contents of a text file to a macro variables without using a data step or a proc import step? My text file contains... Re: PROC DATASETS but only when no errors - comp.soft-sys.sas ...The error condition and message are inputs to the macro so each program can decide what constitutes ... comp.soft-sys.sas ... how to export only few variables using proc ... Where used macro? - comp.cad.solidworks... Errors in Macro A and S - comp.soft-sys.sas How to use macro variable in libname statatement. - comp.soft-sys ... Re: Error when using a macro variable in a PROC IMPORT ... Approaches to Data Transfer from Microsoft Excel® to SAS® V9... file as an example, the following error ... The following is an example of how to use Proc Access to import ... attributes specified in the macro; it has a variable, FLAG ... Paper P0-13 Customizing Proc Import Code Carolyn D. Williams, UNC ...if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */ run; CONCLUSION Customizing Proc Import Code is not and easy solution if ... 7/15/2012 12:26:59 AM
|
|
|
|
|
|
|
|
|