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 (April 2006, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 30 Apr 2006 14:02:28 -0700
Reply-To:     David L Cassell <davidlcassell@MSN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         David L Cassell <davidlcassell@MSN.COM>
Subject:      Re: How to automatically change data name in SET?
In-Reply-To:  <200604301505.k3UAkPvY027943@mailgw.cc.uga.edu>
Content-Type: text/plain; format=flowed

leiliang217@YAHOO.COM wrote: >Hi everyone, > >I have a question. I have a few datasets, say mydata1, mydata2, >mydata3, till mydata&M where M is dymically changing according to >month. For example in March M=3, in April M=4. >So I wrote a program like this but got error message > >DATA SUBRO.RESULT; > DO I = 1 TO &m; > SET SUBRO.MYDATA&I; > END >RUN; > >The effect I want to achieve is that, for example, for m = 3 >DATA SUBRO.RESULT; > SET SUBRO.MYDATA1; > SET SUBRO.MYDATA2; > SET SUBRO.MYDATA3; >RUN; > >for m = 4, it becomes >DATA SUBRO.RESULT; > SET SUBRO.MYDATA1; > SET SUBRO.MYDATA2; > SET SUBRO.MYDATA3; > SET SUBRO.MYDATA4; >RUN; > >Is there any way to do this? > >Thank you!

I see that you have already received a lot of useful advice. But I have some questions.

How do you want to recall recent months? I mean, if you are starting out in January, do you only want one month? Always? It seems to me that you might want the past K months some of the time when you are not in the Kth month of the year.

Why do you have your data stored like this? If you have *all* your months in one data set, then you can subset the data set using a WHERE clause and not need any macro code *at*all*. So I think the key point may be that you have a weak database design that is driving you into these complications.

Suppose you have a data set (or in SAS you can have a data view) that holds every month for you. We'll call it SUBRO.ALLMONTHS . Suppose we have a date variable MyDate in there. Now you can get all the months for this year *in*passing* simply by using a data set option:

(where=(2006=year(MyDate)))

Like this:

proc freq data=SUBRO.ALLMONTHS(where=(2006=year(MyDate))); tables wackyvar1*sillvar2; run;

Now - all of a sudden - your need for a macro solution may be gone.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Don’t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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