Date: Mon, 17 Apr 2000 15:30:54 -0700
Reply-To: latuttle <latuttle@EMAIL.MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: latuttle <latuttle@EMAIL.MSN.COM>
Subject: Re: counts of specific instances
Hi, Emily... there are a number of ways to do this in SAS, and which is
'easiest' depends on what you're used to.
Probably the best way to do this task is PROC FREQ; however, giving you the
exact syntax without seeing how your data is organized isn't so easy. If
you are going to do tasks like this often, probably the best suggestion is
to look up the syntax and experiment with different by variables and tables
statements until you're comfortable with it - trial and error will quickly
teach you how this proc needs to be set up to give you different styles of
output. Essentially, though, PROC FREQ lets you define how you want to
group the data, and counts how many observations fall into each grouping.
If you don't want to invest the time in learning proc freq and you've used
SQL before, PROC SQL can do this with 'select count(select * from mydata
where var1='This' and var2='That') as newvar'. Again, it's a really useful
proc, and if you've used SQL elsewhere, you might find this 'easiest'. If
you aren't familiar with SQL, I'd invest the time in PROC FREQ - SQL's
syntax is different from anything else I've run into in SAS, and debugging
it can be a chore until you get a feel for it.
If neither of those sounds good, you can do this task in a data step. The
only downside is the amount of typing you're going to do to set up the data
step. You'll need a retain statement with every 'count' variable you
define. I'd do it something like this:
data summary (keep=list of variables you want to have in summary dataset,
which will have only one observation);
set mydata end=last;
retain sunday rainday wendday sungame raingame wendgame (etc);
if weather='rain' then do;
if game='yes' then do;
if weekend='yes' then raingmwk=raingmwk+1;
(other if statements that add to counts);
if game='no' then do;
(other statements that add to counts)
if last then output;
Really, the only downside to the last approach is the amount of code you're
going to write (and debug), and the missed opportunity to learn a new
'tool'. If you're going to do much of this sort of thing, getting to know
PROC FREQ will save you a bunch of time later on - and there is some point
where the groupings are complex enough that all those do loops get just too
'loopy' and you need PROC FREQ.
Emily Tang <email@example.com> wrote in message
> Just wondering if anyone knows if SAS is capable of (and if so how best to
> accomplish) the following task:
> I have a dummy dependent variable, let's say it is (RAIN) whether or not
> it rained on a given day.
> I have several dummy indepedent variables as well, say, 1) (WEEKEND) it
> was a weekend, 2) (GAMEDAY) there was a baseball game scheduled.
> I want to get a bar graph or something comparing in absolute number the
> count of #rain days that were also game days, and compare it to #rain days
> that were NOT game days. I am also curious about the incidence of
> weekend days that were gamedays versus weekend days that were not
> Intuition says I should do some kind of if/then statement and tally up my
> combos, but I am not sure of proper syntax, etc..? If I could get the
> proper counts I could graph it in Excel, I just need to know how to get
> counts. In C, I would use a seperate global variable, in SAS, my
> understanding is that all variables are individual to observations.?
> Is this task possible using SAS?
> Thanks for any advice.