I'm trying to find a shorcut around the following. I'm producing a sales report that spans several months, the months will change depending on client request, but the data is structured so each months purchases are on a different dataset...as shown below by my current Libname:
libname a '/data/2006/05/';
libname b '/data/2006/06/';
libname c '/data/2006/07/';
I then pull these with a quick datastep
Is there a short cut or any way of creating a macro to allow me to pick a date range so I won't have to hard code more libnames with each passing month? Thanks!
I don't think to be smarter than Technical Support, but I was thinking that perhaps you could use a macro, like the following:
* Create empty dataset;
create table work.SalesRepTot(Month char(2));
* Loop over the months and simultaneously fill the variable Month;
%do i = &StartMonth %to StopMonth;
%put i = *i.; * Show the value of i in the Log;
libname a "data/2006/&i./";
data work.SalesRepTot; set work.SalesRepTot a.MyMonthFile;
Month = &i.;
libname a clear;
This macro is easy to expand. It could include year as parameter. Or you could include a call to another macro which would create the actual sales report (as a HTML-file?). Hope this helps.
LIBNAME x ('c:\dir1', 'c:\dir2', ..., 'c:\dirn');
So: LIBNAME x ('c:\data\2006\05', 'c:\data\2006\06', 'c:\data\2006\07');
Or you do something like:
LENGTH dir dirs $ 300;
DO yr = 2001 TO 2003; * year directory ;
DO m = 1 TO 12; * month directory;
dir = Quote(Trimn('c:\data\' ||Put(yr,4.0)||'\'||Put(m,z.2)));
IF dirs EQ '' THEN dirs = Trimn(dir);
ELSE dirs = Trimn(dirs) || ',' ||Trimn(dir) ;
Call SymPut('mdirs', dirs);
LIBNAME f (&mdirs);
SET f.file1 f.file2 f.file3;
Haven't tested this so you might have to spruce it up little, but you should get the idea. In particular, you could adapt the above to read inline data.
Depending on the version of SAS you're running, you can also put the name of file directly. But that's another time. Or homework.