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 (December 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 13 Dec 2001 20:01:04 -0500
Reply-To:     Perry Watts <wattsp@DCA.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Perry Watts <wattsp@DCA.NET>
Subject:      Nested Whitlock Do Loops?
Comments: To: kitzmann.daniel@MAYO.EDU
Content-Type: text/plain; charset="iso-8859-1"

Date: Thu, 13 Dec 2001 09:51:43 -0600 From: "Kitzmann, Daniel J." <kitzmann.daniel@MAYO.EDU> Subject: Nested Whitlock Do Loops?

Daniel, In response to: >Can both counters be created in a single data step employing nested special >do loops? For instance, something perhaps in the form of

>data; > do n_genus = 1 by 1 until (last.genus); > do n_species = 1 by 1 until (last.species); > . . . . > end; > end;

The following calculates the number of genera (pl of genus :) ) within a family and the number of species within a genus. Is this what you are looking for?

Perry

data genus; length family genus species $15; input family genus species; cards; Cat HouseCats Tabby Cat HouseCats Persian Cat HouseCats Siamese Cat WildCats Cheetah Cat WildCats Jaguar Cat WildCats Leopard Bear CanadaBear PolarBear Bear USABear BrownBear Bear USABear BlackBear Bear USABear GrizzlyBear Bear FictionBear TeddyBear Bird SmallBird Starling Bird MediumBird Duck Bird MediumBird Goose Bird SmallBird Robin run; proc sort data=genus; by family genus species; run;

*-- the number of genera and species cannot exceed # obs in data set ; proc sql noprint; select left(put(nobs,8.)) into :nobs from dictionary.tables where libname eq 'WORK' and memname eq 'GENUS'; quit;

data countem; do n_genus = 1 to &nobs until (last.family); do n_species = 1 to &nobs until (last.genus); set genus; by family genus; output; end; end; run;

proc print data=countem; title1 'countem: FAMILY and GENUS Counts'; var family genus n_genus species n_species; run;

/****************************************************** Output: countem: FAMILY and GENUS Counts

Obs family genus n_genus species n_species

1 Bear CanadaBear 1 PolarBear 1 2 Bear FictionBear 2 TeddyBear 1 3 Bear USABear 3 BlackBear 1 4 Bear USABear 3 BrownBear 2 5 Bear USABear 3 GrizzlyBear 3 6 Bird MediumBird 1 Duck 1 7 Bird MediumBird 1 Goose 2 8 Bird SmallBird 2 Robin 1 9 Bird SmallBird 2 Starling 2 10 Cat HouseCats 1 Persian 1 11 Cat HouseCats 1 Siamese 2 12 Cat HouseCats 1 Tabby 3 13 Cat WildCats 2 Cheetah 1 14 Cat WildCats 2 Jaguar 2 15 Cat WildCats 2 Leopard 3 *****************************************************/

-------------------------- Perry Watts wattsp@dca.net --------------------------


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