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 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 7 Jul 2009 04:37:48 -0400
Reply-To:     Lou <lpogoda@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Lou <lpogoda@HOTMAIL.COM>
Organization: A noiseless patient Spider
Subject:      Re: SAS macro
Comments: To: sas-l@uga.edu

"Melodyp" <pearsonmelody@gmail.com> wrote in message news:1af8f9fe-0c8d-4dd7-9003-57ff82d7be73@s1g2000prd.googlegroups.com... > I have 5 dataset contains same variables with different months > information, month is not a variable in the file. > > I need to append these file together and want to also keep the > information that which observations come from which file, so I have to > create an additional filed for each file using the following code: > > data mylib.REPORT_JAN_09_new; > set mylib. REPORT_JAN_09; > month=Jan; > > data mylib.REPORT_Feb_09_new; > set mylib. REPORT_Feb_09; > month=Jan; > then do it for March... July, it's quit laboring, is there anyway I > can using a macro do it in batch? >

You're making it too hard. Try some simple code;

data allmonths; set mylib.report_jan_09 (in = jan) mylib.report_feb_09 (in = feb) mylib.report_mar_09 (in = mar); if jan then month = 'Jan'; if feb then month = 'Feb'; if mar then month = 'Mar'; run;

That doesn't look very laborious - it's pretty simple to copy rows as needed to add more months, though if you have a few years' worth of datasets it may be work automating. Assuming all the datasets you want to append are in one library, something like the following untested code should do the trick.

proc sql noprint; select 'mylib.' || trim(memname) || ' (in = ' || substr(memname, 8, 3) || ')' into :mylibs separated by ' ' from dictionary.tables where lowcase(libname) = 'mylib'; select 'if ' || substr(memname, 8, 3) || ' then month = "' || substr(memname, 8, 3) || '";' into :ifs separated by ' ' from dictionary.tables where lowcase(libname) = 'mylib'; quit; data allmonths; set &mylibs; &ifs; run;


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