Discussion:
How to use macro variable in libname statatement.
(too old to reply)
SUBSCRIBE SAS-L Joe H. Smith
2010-01-07 11:01:18 UTC
Permalink
HI all,

I want to use macro variable in libname statement.

%let
path=/sasconf/Dev/Lev1/SASMain/C/QUARTER/STF_TEST/&&a&i/Fcst_gp_spec
_item_fac_lev3;

libname test &path.;

i am creating macro variable from below code...

%macro mahesh;
PROC SQL noprint;
select new_group into :a1-:a200 from trans;
select count(*) into :cnt from trans;
/*drop table outmodelinfo;*/
%do i = 1 %to &cnt;
%PUT "&&a&i";

%end;
quit;
%mend mahesh;

above macro gets me values for &&a&i.

i hope i am using macro variable wrongly in libname statement.

Please help out.

gives me folowing error,...

WARNING: Apparent symbolic reference I not resolved.
WARNING: Apparent symbolic reference A not resolved.
WARNING: Apparent symbolic reference I not resolved.
14 %let
path=/sasconf/BEMLDev/Lev1/SASMain/C/QUARTER/STF_TEST/&&a&i/Fcst_gp_
spec_item_fac_lev3;
ERROR: Libref in LIBNAME statement must be followed either by quoted string or
engine name or semicolon; "/" found.
ERROR: Error in the LIBNAME statement.
WARNING: Apparent symbolic reference A not resolved.
WARNING: Apparent symbolic reference I not resolved.
Tom Abernathy
2010-01-07 13:59:27 UTC
Permalink
I see two issues. The easy one is to put double quotes around the path
in your LIBNAME statement.
The second is access to the I and A1 to A... macro variables. If you
are really generating them with the SQL statement inside that macro
they will be defined as local to that macro and thus "disappear" when
the macro ends. You can test this by doing %put &path.

You can solve this by moving the libname statement into the macro or
adding a %GLOBAL statement to force the macro variables to be defined
in the global name space, or defining the macro variables before
calling the macro.
Post by SUBSCRIBE SAS-L Joe H. Smith
HI all,
I want to use macro variable in libname statement.
%let
path=/sasconf/Dev/Lev1/SASMain/C/QUARTER/STF_TEST/&&a&i/Fcst_gp_spec
_item_fac_lev3;
libname test &path.;
i am creating macro variable from below code...
%macro mahesh;
PROC SQL noprint;
select new_group into :a1-:a200 from trans;
select count(*) into :cnt from trans;
/*drop table outmodelinfo;*/
%do i = 1 %to &cnt;
%PUT "&&a&i";
%end;
quit;
%mend mahesh;
above macro gets me values for &&a&i.
i hope i am using macro variable wrongly in libname statement.
Please help out.
gives me folowing error,...
WARNING: Apparent symbolic reference I not resolved.
WARNING: Apparent symbolic reference A not resolved.
WARNING: Apparent symbolic reference I not resolved.
14         %let
path=/sasconf/BEMLDev/Lev1/SASMain/C/QUARTER/STF_TEST/&&a&i/Fcst_gp_
spec_item_fac_lev3;
ERROR: Libref in LIBNAME statement must be followed either by quoted string or
engine name or semicolon; "/" found.
ERROR: Error in the LIBNAME statement.
WARNING: Apparent symbolic reference A not resolved.
WARNING: Apparent symbolic reference I not resolved.
Loading...