Jules,
Seems your taking the long way to get to were you want to go to, in
order to make my code work.
What is needed is the following SQL statement:
Proc SQL noprint;
Select mamname into : mem_list separated by " "
From sashelp.vcolumn
Where libname = "your libname here";
%let stop = &sqlobs;
Quit;
%macro merge_demo;
Data bigfile;
merge demofile (in=a)
%do I = 1 to &stop;
%let dsn = %scan(<your macro var>, &I);
&dsn (in=b rename = (newvar = &dsn._newvar) keep=(id trial
&dsn._newvar));
%end;
by id trial;
run;
%mend merg_demo;
%merg_demo;
Toby Dunn
-----Original Message-----
From: Bosch, Jules [PRDUS Non J&J] [mailto:***@PRDUS.JNJ.COM]
Sent: Tuesday, June 29, 2004 9:43 AM
To: Dunn, Toby; SAS-***@listserv.uga.edu
Subject: RE: Loop to merge multiple datasets to one dataset
Dan,
Some of the following SAS code may be helpful. With this code you don't
need to know how many members are in the library or their names,
assuming you want to process ALL members in the library.
HTH,
Jules Bosch
dm 'clear out'; dm 'clear log';
libname mylib '...';
/***********************************************************************
**
Use the SAS Data Dictionary to create a data set with all library
member names. LIBNAME must be available.
************************************************************************
*/
%macro strings(dir);
proc sql noprint;
create table work.mem as
select memname,
count(memname) as cnt
from dictionary.tables
where libname="&dir";
quit;
run;
title1 "&dir members from Data Dictionary";
proc print data=work.mem; run;
%mend strings;
%strings(MYLIB);
/***********************************************************************
**
Create a sequential macro var for each data set.
************************************************************************
*/
%macro worklist;
%global cntlist;
data _null_;
set work.mem end=eof;
call symput('dsn'||left(put(_n_,3.0)),left(trim(memname)));
if (eof) then call
symput('cntlist',put(_n_,3.0));
run;
%mend worklist;
%worklist;
%put &cntlist;
/***********************************************************************
**
Display each macro var on the SASlog.
************************************************************************
*/
%macro showlist;
%do i=1 %to &cntlist;
%put Data Set Name: &&dsn&i;
%end;
%mend showlist;
%showlist;
/***********************************************************************
**
Merge (or coancatenate???) the data sets. Is the variable common to
each data set of the same name? If so, a rename will be necessary.
************************************************************************
*/
Toby Dunn's code will then work here.
-----Original Message-----
From: Dunn, Toby [mailto:***@TEA.STATE.TX.US]
Sent: Tuesday, June 29, 2004 9:57 AM
To: SAS-***@listserv.uga.edu
Subject: Re: Loop to merge multiple datasets to one dataset
Dan,
Try using a SQL statement with an into : <macro variable> to get your
datasets from your library.
Then if your goal is to merge them all together in one huge file with
demofile do something like the following;
%macro merge_demo;
Data bigfile;
merge demofile (in=a)
%do I = 1 to &stop;
%let dsn = %scan(<your macro var>, &I);
&dsn (in=b rename = (newvar = &dsn._newvar) keep=(id trial
&dsn._newvar));
%end;
by id trial;
You will noticed I renamed your newvar variable. I assumed that all
datasets to be merged had the same var and you have to have some way to
distinguish them from one another or they will be overwritten by the
next data set.
HTH
Toby Dunn
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of Dan
Litsky
Sent: Tuesday, June 29, 2004 8:35 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Loop to merge multiple datasets to one dataset
I have 250 datasets in one directory all starting with the letters "ds"
and numbered semi-sequentially. So there is a ds1 ds2 ds5 ds8, etc.
There are "holes" in the numbers.
I want to merge all of these datasets to one dataset containing
demographic information. The multiple datasets all contain one field
that I need on the new large dataset.
My merge might look like this:
Data bigfile;
merge demofile (in=a)
ds1 (in=b keep=(id trial newvar));
by id trial;
I'd like to read through the entire directory and merge in a loop if I
could. Is there a way to do this? I've check through the archives but
must be using the wrong set of search words because I can't find
anything that applies.
Thanks,
Dan
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!