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 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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; raingame=raingame+1; if weekend='yes' then raingmwk=raingmwk+1; (other if statements that add to counts); end; if game='no' then do; (other statements that add to counts) end; end;

.... if last then output; run;

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.

Good luck,

Laura

Emily Tang <yet@duke.edu> wrote in message news:Pine.SOL.3.91.1000416220522.25259E-100000@soc16.acpub.duke.edu... > > Hi, > > 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 gamedays. > > 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. > > Emily


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