Date: Tue, 18 Jan 2011 09:24:18 -0500
Reply-To: "Teed, Lionel" <Lionel.Teed@TD.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Teed, Lionel" <Lionel.Teed@TD.COM>
Subject: Re: equal 5 or not, easier way?
In-Reply-To: <451C22294BD94891AC242158F3010139@D1871RB1>
content-type: text/plain; charset="ISO-8859-1"
I agree with Art's prior note, and Mike's post.
This is a pretty neat use of an array. I am going to have to put that on the "Did you know..." list for sometime in the future where I am sure that I can use it!
Lionel
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nat Wooding
Sent: Tuesday, January 18, 2011 9:08 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: equal 5 or not, easier way?
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
NOTICE: Confidential message which may be privileged. Unauthorized use/disclosure prohibited. If received in error, please go to www.td.com/legal for instructions.
AVIS : Message confidentiel dont le contenu peut être privilégié. Utilisation/divulgation interdites sans permission. Si reçu par erreur, prière d'aller au www.td.com/francais/avis_juridique pour des instructions.