Date: Wed, 11 Aug 2004 17:32:38 GMT
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: Macro to create libnames and librefs
Richard and Toby (who responded off line),
First, while I agree with Richard that my code is unnecessarily wasteful, I
was mostly interested in why it wasn't working. As for better solutions,
Richard's and Glenn's were far more elegant than mine (which is why I stick
to psychology and statistics rather than programming).
Toby discovered why my original code wasn't working, namely that the 'run'
statement was misplaced .. it had to be placed before the libname statement
as shown below:
filename keylist PIPE "dir c:\200* /ad /on /b";
data one;
infile KEYLIST;
input filename;
CALL SYMPUT('NumFiles',_n_);
run;
%macro makelbn;
%do i=1 %to &NumFiles;
data _null_;
set one (firstobs=&i obs=&i);
ln = trim('x'||trim(left(filename)));
dn = trim('c:\'||trim(left(filename)));
CALL SYMPUT('ln',ln);
CALL SYMPUT('dn',dn);
run;
libname &ln "&dn";
%end;
%mend;
%makelbn
It wouldn't work, previously, because (quoting Toby):
"Notice the placement of the run statement, you can't use the macro vars
until the next step boundry."
|