Date: Tue, 18 Jan 2011 09:07:39 -0500
Reply-To: Nat Wooding <nathani@VERIZON.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <nathani@VERIZON.NET>
Subject: Re: equal 5 or not, easier way?
In-Reply-To: <037AB3FF38D44C4BAFB5DFF3D06B57BAA71DA0FA@EX-CMS01.westat.com>
Content-Type: text/plain; charset="US-ASCII"
Mike
I would allow an array here since you are not using a loop to examine each
element.
I just verified that it will not recognize a 15 or other multidigit number
that contains a 5.
Thanks for reminding me about this use of the In function.
Nat
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mike
Rhoads
Sent: Tuesday, January 18, 2011 8:37 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: equal 5 or not, easier way?
I know you're not supposed to use an array, but I have to admit I like the
following construct (which was actually new to me):
Data _null_;
input q1-q5;
array a {*} q1-q5;
flag = (5 in a);
put _all_;
datalines;
1 2 3 4 5
6 7 8 9 10
run;
Mike Rhoads
RhoadsM1@Westat.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nat
Wooding
Sent: Monday, January 17, 2011 6:25 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: equal 5 or not, easier way?
Max
The Index function will work for you. I was lazy and used the cat function
rather than one where I would have to supply a separator.
Nat
Data max;
informat q1-q5 $1.;
input q1 - q5;
if index( cat(of q: ), '5' ) then flag = 1;
cards;
1 2 3 4 5
6 7 8 9 10
run;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of bbser
2009
Sent: Monday, January 17, 2011 6:02 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: equal 5 or not, easier way?
Joe
I tried something like this, but failed.
if catx(" ", of q1-q5) contains "5" then ...
it seems that contains/? can not be used with if-statement?
Max
From: Joe Matise [mailto:snoopy369@gmail.com]
Sent: January-17-11 5:38 PM
To: bbser 2009
Cc: SAS-L@listserv.uga.edu
Subject: Re: equal 5 or not, easier way?
Not sure what Cody is suggesting, but there's an easy way with CATX
function... can you see it?
-Joe
On Mon, Jan 17, 2011 at 4:16 PM, bbser 2009 <bbser2009@gmail.com> wrote:
q1-q5 are all numeric variables,
WITHOUT using array,
I would like to see if any of them equals 5.
Cody's book says this can be easily done using OR or IN operators.
I do not see how this can be easily done except for the "non-easy" way like
this "if q1=5 or q2=5 or ..."
I tried something like this:
if (q1-q5) (or in) (5) then ...
Which of course does not work, but hopefully this helps you understand what
I am looking for.
Please help. Thanks.
Max