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 (January 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 11 Jan 2006 14:41:44 -0800
Reply-To:     "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Subject:      Re: Loop through data sets
Comments: To: jjj912@YAHOO.COM
Content-Type: text/plain; charset="us-ascii"

Hi,

Using a macro can replicate the canned text while replacing certain pieces each time:

data old1; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; run;

data old2; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; run;

data old3; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; some_variable = 0; output; some_variable = 1; output; some_variable = 2; output; run;

%macro dothem(theIdx); data new&theIdx; set old&theIdx; if some_variable > 0 then do; some_variable= 123; output new&theIdx; end; run; %mend;

option mprint;

%dothem(1) %dothem(2) %dothem(3)

--or--

%macro doall; %do _i = 1 %to 3; %dothem(&_i) %end; %mend;

%doall

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jjj912@YAHOO.COM Sent: Wednesday, January 11, 2006 2:28 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Loop through data sets

How do I loop through several existing datasets, perform an operation on each, and then save the modified dataset as a new dataset?

Here's some code that illustrates what I want to accomplish:

data ; do i = 1 to 3; /* Loop through existing datsets */ set old[i]; /* Contains a list of old datasets */ if some_variable >0 then do some_variable= 123; /* perform an operation */ output new[i]; /* Output data to a new dataset */ end; end; run;

Thanks,


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