Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2006, 05:48 PM
Droogendyk, Harry
Guest
 
Posts: n/a
Default Re: Nested if-then-do

Go to http://lexjansen.com/sugi/ and enter 'debugging' in the search
box. A bunch of good SUGI papers for your perusal.

-----Original Message-----
From: owner-sas-l@listserv.uga.edu [mailtowner-sas-l@listserv.uga.edu]
On Behalf Of dave crimkey
Sent: 2006, February, 04 1:33 PM
To: tobydunn@hotmail.com; SAS-L@LISTSERV.UGA.EDU
Subject: RE: Nested if-then-do

I thought about an array based solution but thought it would be the same
amount of code. I only have one "count" I want to keep track of and
that is a count of the number of same types. If atype = 180 and btype =
180 and ctype = 180 -- count would be 3. If atype = 50 and btype = 60
and atype = 50 count would be 2.

Other than put statements are there any debugging techniques I can use
in SAS?

toby dunn <tobydunn@hotmail.com> wrote:
Dave ,

How you want to count the nonmissing types is a little fuzzy but see if
this gets you started:

DATA test ;
infile cards ;
INPUT id atype btype ctype dtype ;
CARDS ;
1 180 180 17 .
3 60 . . 60
4 60 80 80 30
17 14 50 14 53
33 . 5 . 72
49 24 . 24 75
65 . 52 52 .
81 5 44 11 44
2 24 . 24 .
18 40 40 14 40
34 . 47 47 .
50 . 35 17 57
66 22 . . .
;
run ;

data two ( drop = i ) ;
set test ;
array types (4) atype btype ctype dtype ;

SameTypes = 0 ;
NonMissing = 0 ;


do I = 1 to dim(types) ;
if ( not missing(types(i)) ) then nonmissing + 1 ; end ;

do I = 2 to dim(types) ;
if ( types(1) = types(i) ) then SameTypes + 1 ; end ;

do I = 3 to dim(types) ;
if ( types(2) = types(i) ) then SameTypes + 1 ; end ;

if ( types(3) = types(4) ) then SameTypes + 1 ;

if SameTypes in ( 1 , 2 ) then SameTypes = SameTypes * 2 ; run ;



proc print
data = two ;
run ;




Toby Dunn





From: dave crimkey
Reply-To: dave crimkey
To: SAS-L@LISTSERV.UGA.EDU
Subject: Nested if-then-do
Date: Sat, 4 Feb 2006 08:46:08 -0800

I'm trying to run through a dataset and count cases where the "types"
are the same.
I have four types that I'm looking through and when any one of the types
is the same as any of the other types its counted as two counts (two
types are the same). If three types are the same its counted as three
types (three types are the same) and so on.
The problem is that if there are four types and the middle two are the
same, the code is not falling through to pick up the count.
I'm not sure about SAS if-then-do. The following is my code and the
result. I hope my indenting works in this email. Can anyone help? Is
there a better way to do this?
DATA work.survey ;
INPUT id 1-3 atype 6-8 btype 10-12 ctype 14-16 dtype 17-19 acount 21-21
bcount 23-23 ccount 25-25 dcount 27-27; allcount = acount + bcount +
ccount + dcount; CARDS ;
1 180 180 17 1 1 1 0
3 60 60 1 0 0 1
4 60 80 80 30 1 1 1 1
17 14 50 14 53 1 1 1 1
33 5 72 0 1 0 1
49 24 24 75 1 0 1 1
65 52 52 0 1 1 0
81 5 44 11 44 1 1 1 1
2 24 24 1 0 0 1
18 40 40 14 40 1 1 1 1
34 47 47 0 1 1 0
50 35 17 57 0 1 1 1
66 22 1 0 0 0
PROC PRINT ;
RUN ;
data stst;
set work.survey;
if acount = . then acount = 0;
if ccount = . then ccount = 0;
if dcount = . then dcount = 0;
if bcount = . then bcount = 0;

if acount > 0 then do;
if bcount > 0 and (btype = atype) then do ; if ccount > 0 and (ctype =
atype) then do; if dcount > 0 and (dtype = atype) then count = 4; else
count = 3; end; else do; if dcount > 0 and dtype = atype then count = 3;
end; end; else do; if ccount > 0 and ctype = atype then do; if dcount >
0 and dtype = atype then count = 3; else count = 2; end; else do; if
dcount > 0 and dtype = atype then count = 2; end; end; end; else do; if
bcount > 0 then do; if ccount > 0 and ctype = btype then do; if dcount >
0 and dtype = btype then count = 3; else count = 2; end; else do; if
dcount > 0 and dtype = btype then count = 2; end; end; else do; if
ccount > 0 then do; if dcount > 0 and ctype = dtype then count = 2; end;
end; end; run; proc print data= stst noobs ; var atype btype ctype dtype
allcount count; run; atype btype ctype dtype allcount count 180 180 17 .
3 .
60 . . 60 2 2
60 80 80 30 4 .
14 50 14 53 4 2
.. 5 . 72 2 .
24 . 24 75 3 2
.. 52 52 . 2 2
5 44 11 44 4 .
24 . . 24 2 2
40 40 14 40 4 3
.. 47 47 . 2 2
.. 35 17 57 3 .
22 . . . 1 .




---------------------------------
Brings words and photos together (easily) with PhotoMail - it's free and
works with Yahoo! Mail.




__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
yahoo.com" target="_blank">http://mail.yahoo.com
__________________________________________________ _____________________

This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations.
Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized.
If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.

Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite.
Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser immédiatement, par retour de courrier électronique ou par un autre moyen.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: BSF4Rexx problem with nested invocations rony Newsgroup comp.lang.rexx 2 03-31-2009 03:49 PM
Re: nonlinear nested mixed effects model Dave Fournier Newsgroup comp.soft-sys.sas 0 03-11-2009 08:45 PM
Re: invoking a macro with nested macros within a sas proc David L Cassell Newsgroup comp.soft-sys.sas 0 08-24-2007 05:49 AM
Re: invoking a macro with nested macros within a sas proc Rushi Patel Newsgroup comp.soft-sys.sas 0 08-22-2007 04:44 PM
SCL Joe (was RE: macro structure) Gregg P. Snell Newsgroup comp.soft-sys.sas 0 06-27-2006 07:59 PM



All times are GMT. The time now is 06:51 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.