|
Ya, Quentin, and Paul have stolen the show. The solution that I had in mind,
data abc (drop=str);
input subject mon1 mon2 mon3 mon4 @3 str $7.;
enter=input(substr(compress(str,' 0'),1,1),1.);
datalines;
1 0 0 2 0
2 2 0 5 0
3 4 2 7 0
4 0 1 5 0
5 2 3 . 7
;
run; ,
obviously depends on the constraint that the input line (in the form of a
crude array) consists of single digits separated by blanks (forget signed
digit strings). I don't see that it would be that easy to extend to numeric
sequences in general.
Ya, I have to ask this. Do you happen to have a brother also called Ya (in
the style of Chinese surnames appearing first in the full name)? If so, you
might have a movie sequel in your future.
Sig
-----Original Message-----
From: Dorfman, Paul [mailto:Paul.Dorfman@BCBSFL.COM]
Sent: Thursday, June 13, 2002 12:51 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: FW: repost : how to get a non zero value for each obs (
chall e nge problem)
Sig,
I have thought of this, but abstained - not because of the repeated PUT()
calls, but because the solution presumes the ahead-of-the-time knowledge
about the number of digits in each number. Using the expression
input(left(tranwrd(peekc(addr(mon1),32),put(0,rb8.),'')),rb8.) ;
does not. In fact, non-zero elements can assume any numeric value at all.
Kind regards,
====================
Paul M. Dorfman
Jacksonville, FL
====================
> -----Original Message-----
> From: Sigurd Hermansen [mailto:HERMANS1@WESTAT.COM]
> Sent: Thursday, June 13, 2002 11:40 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: FW: repost : how to get a non zero value for each obs (
> challe nge problem)
>
>
> Quentin McMullen sent this one variable definition, no array,
> and no loop
> solution directly to me:
>
> data abc;
> input subject mon1 mon2 mon3 mon4 ;
>
> enter=input(compress(put(mon1,1.)||put(mon2,1.)||put(mon3,1.)|
> |put(mon4,1.),
> '0'),1.);
> datalines;
> 1 0 0 2 0
> 2 2 0 5 0
> 3 4 2 7 0
> 4 0 1 5 0
> 5 2 3 . 7
> ;
> run;
>
> His solution has one less variable definition than the one I
> have in mind.
> One drawback: it repeats the calls of the PUT() function.
>
> Anyone else accept the challenge?
>
> Sig
>
> -----Original Message-----
> From: Andreas Gr|ninger [mailto:andreas.grueninger@LFL.BWL.DE]
> Sent: Thursday, June 13, 2002 8:02 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: FW: repost : how to get a non zero value for each obs
>
>
> Your and Paul's solution (sligthly modified ) gives a
> one-step solution
> without additional variables.
>
> data abc;
> input subject mon1 mon2 mon3 mon4 ;
> ARRAY mon mon:;
> DO OVER mon;
> IF (mon > 0) THEN DO;
> enter = mon;
> LEAVE;
> END;
> END;
> datalines;
> 1 0 0 2 0
> 2 2 0 5 0
> 3 4 2 7 0
> 4 0 1 5 0
> 5 2 3 . 7
> ;
> run;
>
Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
affiliate companies are not responsible for errors or omissions in this
e-mail message. Any personal comments made in this e-mail do not reflect the
views of Blue Cross Blue Shield of Florida, Inc.
|