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 (October 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 22 Oct 2006 01:26:40 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: macro variables, same data step, multiple outputs
Comments: To: datamatter@GMAIL.COM
In-Reply-To:  <1161469197.371070.85350@k70g2000cwa.googlegroups.com>
Content-Type: text/plain; format=flowed

DataMatter ,

It can be done however not how you think. Due to the fact that the data sets you want created and the output statements will have to be specified before the data step spits it out to these data sets you are looking at least two passes of the data.

Personally I wouldnt break the data up unless I was requested too as it only makes working with teh data harder and you will always end up with a greater volume of code as well as moe complex code.

Here some code that does what you want I will leave it to you to optimze:

Data Have ; Do I = 1 to 20 ; Output ; End ; Run ;

%Macro DataNeed( DSN = , Name = ) ; Data Need&Name ; Set &DSN ; Where I = &Name ; Run ; %Mend DataNeed ;

Data Prep ; Set Have ;

If ( 1 <= I <= 5 ) Then Index = 1 ; Else If ( 6 <= I <= 10 ) Then Index = 2 ; Else If ( 11 <= I <= 15 ) Then Index = 3 ; Else If ( 16 <= I <= 20 ) Then Index = 4 ;

Run ;

Data _Null_ ; Set Prep ; By Index ;

If First.Index Then Call Execute( '%NrStr( %DataNeed( DSN = Have , Name = ' || Put( Index , 8. -L ) || ') )' ) ;

Run ;

Toby Dunn

The obscure we see eventually. The completely obvious, it seems, takes longer. ~Edward R. Murrow

Think like a man of action, act like a man of thought. ~Henri Louis Bergson

Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don't know," Alice answered. "Then," said the cat, "it doesn't matter." ~Lewis Carroll, Alice in Wonderland

From: datamatter@GMAIL.COM Reply-To: datamatter@GMAIL.COM To: SAS-L@LISTSERV.UGA.EDU Subject: macro variables, same data step, multiple outputs Date: Sat, 21 Oct 2006 15:19:57 -0700

I'm trying to create multiple output data sets (called m1, m2, m3, etc.) but have SAS compute for each row of input data which output data set to place the record in.

For example, during the data step, SAS will compute a variable called index. If index=3, then the record will be placed in output set named "m3" and so on.

I'm having trouble because I need to dynamically generate output statements of the form "output m1" or "output m2", etc. based on the computed index.

I tried two methods, neither works. 1) If I use call symput to set the index as a macro variable, it fails because I can't use that macro variable within the same data step. I can't put the output statement in a different data step because that would not work for this purpose.

2) I tried to create an array with character values m1, m2, m3, and then invoke the output statement. However, it seems like array references do not work with output statements. array m[&max_index] (m1 m2 m3 ...) x = some calculation leading to the index value output m[x] does not work although put m[x] prints out as m1 if x = 1 etc.

Any help would be appreciated.

DM

_________________________________________________________________ Try Search Survival Kits: Fix up your home and better handle your cash with Live Search! http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=hmtagline


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