LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 9 Feb 2001 13:31:47 -0500
Reply-To:     "Dorfman, Paul" <paul.dorfman@CITICORP.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Dorfman, Paul" <paul.dorfman@CITICORP.COM>
Subject:      Re: Frequency by season
Comments: To: "estreltsov@eurocomix.net" <estreltsov@eurocomix.net>
Content-Type: text/plain

Ed,

It should not be too hard to concoct. First, you can use the facts that:

1) a SAS array can refer to the same variable more than once 2) the same variable can be incorporated in more than one array

With that in mind:

data _null_; array months (*) winter winter spring spring spring summer summer summer autumn autumn autumn winter; array season (*) winter spring summer autumn; if end then put (season(*)) (=); set dates end=end; months (month(date)) ++ 1; run;

Actually, the second array, SEASON, is needed only for the convenience of printing. You could omit it and still print the stuff as

put put (winter spring summer autumn) (=);

Secondly, if you are rather mathematically inclined, there is a shorter solution:

data _null_; array season (0:3) winter spring summer autumn; if end then put (season(*)) (=); set dates end=end; season (mod(month(date),12)/3) ++ 1; run;

Here, the array SEASON is of course needed. MOD(MONTH(DATE),12) produces 0 to 12 for Dec to Nov; division by 3 throws the stuff in 4 buckets from 0.xxx to 3.xxx; and because the expression is used as an index into SEASON, the decimal part is chopped off. The rest is trivial.

Kind regards, =============================== Paul M. Dorfman Citibank/AT&T Universal Card Jacksonville, Fl ===============================

> -----Original Message----- > From: Eduard Streltsov [SMTP:estreltsov@eurocomix.net] > Sent: Friday, February 09, 2001 1:15 PM > To: sas-l@listserv.uga.edu > Subject: Frequency by season > > Hi, > > I've got a SAS file DATES with a variable DATE which is a SAS date. The > values of DATE span several years across the observations. I also have > four seasons defined as: > > winter -> 01dec thru feb > spring -> 01mar thru may > summer -> 01jun thru aug > autumn -> 01sep thru nov > > What I have to do is print number of dates that fall into each season > (frequency by season) like this: > > winter=123 spring=456 summer=789 autumn=258 > > If a season has nothing in it, a missing (.) should print. I've come up > with a pretty ugly pile of if-then-elses. I will appreciate any > professional, elegant example of how to do it. >


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