LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 22 Jul 1999 14:47:26 -0400
Reply-To:     "Fehd, Ronald J." <rjf2@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Fehd, Ronald J." <rjf2@CDC.GOV>
Subject:      Re: Concatenate all files in a library?
Comments: To: "pem@theriver.com" <pem@theriver.com>
Content-Type: text/plain; charset="iso-8859-1"

From: Patrick E. McKnight [mailto:pem@theriver.com] /I have a macro that runs several hundred iterations and outputs /data files with the results to a specified library that only contains /these output files. What I would like to do is to concatenate them /into one large file for later analysis.

BTDT: Been There, Doing That. ;-)

/Is this possible without having /to do some extensive programming?

Depending on your tool box.

/If no simple solution exists then what I figured I would do is take a /list of the directory's contents (the *.sd* files - this is Windows and /SAS ver 6.12), create a sas dataset comprised of the list of files /with trimmed extensions, and then use those elements of the /dataset to form the contents of the set command in a data step. /Any advice that would simply this process would be greatly /appreciated.

You've got the right idea. A general solution is always preferred. So: back to the tool box. *get a list of data set names from library %MACRO WHATEVER(_); %MEMNAMES(LIBRARY=<SUMMARY-LIBRARY-NAME>);run; *you now have not only a data set with the member names *but a macro array! how nice!; DATA SUMMARY; do until(EndoFile); set %DO I = 1 %TO &DIM_DSN.; &&DSN&I %END; end = EndoFile; output;end;stop;run; proc PRINT; %MEND;%WHATEVER;

You're responsible for being sure that all those data sets have the same structure!

Ron Fehd the toolbox maven CDC Atlanta GA

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * MACRO MEMNAMES * from MACARRAY: a tool to store data_set names in a macro "array" * by Frank C. DiIorio, ASG, Inc., Cary, NC * SESUG4 96: pg 229-231 * Proceedings of the Fourth Annual * SouthEast SAS Users Group Conference * * returns data set with names of members in LIBRARY * RJF2:96Dec19 * vars are same as proc CONTENTS * to see all vars available: ** select * ** from dictionary.tables RJF2 97Jul25 added parm ARRAY-name uses both NOBS and DIM_&ARRAY to get DIM_&ARRAY into scope of calling program RJF2 97Aug11 added options: store, des= RJF2 98Dec31 does not handle obs=0 calling program must initialize DIM_DSN NOTE: CALLING MACROS _MUST_: 1. have at least one parm, this creates local symbol table 2. be immediately followed by 'run;' statement before DIM_DSN can be used in a %DO loop * see difference between CHK2 and CHK3 in testing below * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ %macro MEMNAMES(LIBRARY=LIBRARY ,ARRAY=DSN ,OUT=MEMNAMES ,KEEP=. ,WHERE=. ) /*store and des disabled for SAS-L posting /store des = 'returns mac-array DSN: MEMNAMES.MemNames' /**/ ;/*--------------------------------------------------------*/

%local NOBS;%*but DIM_&ARRAY is available to calling program/macro;

proc SQL noprint; create table &OUT.(keep = MemName MemLabel Nobs %IF "&KEEP" ne "." %THEN &KEEP.; ) as select MemType, Libname, MemName, MemLabel, Nobs, Nvar from dictionary.tables where MemType = 'DATA' and Libname = "%UPCASE(&LIBRARY.)" %IF "&WHERE" ne "." %THEN and &WHERE.; ; select nobs into :NOBS from dictionary.tables where MemType = 'DATA' and Libname = "WORK" and MemName = "&OUT."; quit;

DATA _NULL_;%LET DIM_&ARRAY = 0; %IF &NOBS. %THEN %DO; retain N 0; do until(EndoFile); set &OUT. end = EndoFile; N + 1; call symput("&ARRAY" !! trim(left(put(N,3.))),trim(MemName)); end; call symput("DIM_&ARRAY",trim(left(put(N,3.))) );%END; %ELSE %DO;%*ET DIM_&ARRAY = 0; %END; stop; %ENDOMAC:; %*...............................................*; %MEND; /********************************************************** options nocenter mprint; *MEMNAMES;run;*create global mac-vars; %PUT DIM_DSN = <&DIM_DSN.>; %MACRO CHK1();%*show global mac-vars; %DO I = 1 %TO &DIM_DSN;%put <&I = &&DSN&I.; %END;%MEND; *CHK1; %MACRO CHK2(); %*creates global mac-vars because no local symbol table; %MEMNAMES(ARRAY=XYZ,WHERE=substr(MemName,1,1) eq 'P');run; %DO I = 1 %TO &DIM_XYZ;%put <&I = &&XYZ&I.>; %END;%MEND; *CHK2; %PUT DIM_XYZ = <&DIM_XYZ.>; %MACRO CHK3(A);*create local mac-vars; %MEMNAMES(ARRAY=ABC,WHERE=substr(MemName,1,1) eq 'L');run; %DO I = 1 %TO &DIM_ABC;%put <&I = &&ABC&I.>; %END;%MEND; %CHK3; %PUT DIM_ABC = <&DIM_ABC.>; *WARNING: Apparent symbolic reference DIM_ABC not resolved.; *MEMNAMES(where=substr(MemName,1,1) eq 'C');run; *MEMNAMES(keep = NVAR,where=substr(MemName,1,1) eq 'H');run; *proc PRINT data = WORK.MEMNAMES; *proc CONTENTS data = WORK.MEMNAMES; run; /*******************************************************/


Back to: Top of message | Previous page | Main SAS-L page