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
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.
>