Date: Wed, 14 Feb 2007 14:47:32 -0500
Reply-To: Nathaniel.Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject: Re: Coding string/character vars
In-Reply-To: <589001.22181.qm@web62211.mail.re1.yahoo.com>
Content-Type: text/plain; charset="UTF-8"
Syb
Try the following. Also, may I suggest that you not start your subjects
with Re: since that it typically prepended to subject lines when someone
replies to a question and people may skip your questions thinking that an
answer has been given -- I least, I sometimes do this.
Nat Wooding
Environmental Specialist III
Dominion, Environmental Biology
4111 Castlewood Rd
Richmond, VA 23234
Phone:804-271-5313, Fax: 804-271-2977
Data punt;
informat color $25.;
input color;
cards;
Red
Orange
Yellow
Green
Blue
Indigo
Violet
BlackBrown
YellowGreen
RedGreen
YellowRedGreen
RedIndigoGreen
GreenRedBrown
___GreenRed
RedGreen__
data fieldgoal;
set punt;
if color = 'Green' then
code =1;
else if color in ('GreenRed','RedGreen') then code =2;
else if color in ('GreenYellow','YellowGreen') then code =3;
else if INDEX(color,'Red') and index(color,'Green') then code = 4;
else code = 0;
run;
proc print;
run;
Syb it
<sas_datalover@YA
HOO.COM> To
Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
Discussion" cc
<SAS-L@LISTSERV.U
GA.EDU> Subject
Re: Coding string/character vars
02/14/2007 01:03
PM
Please respond to
Syb it
<sas_datalover@YA
HOO.COM>
Dear List,
Consider this scenario:
Lets one wanted to code data this way
Char Var
Code
Green
Green only
1
GreenRed
Green + Red
2
RedGreen
Red + green
2
GreenYellow
Green + Yellow
3
YellowGreen
Yellow + Green
3
GreenRedAnycolor
Red, Green + any color
4
AnycolorGreenRed
Any color + Red, Green
4
Else
The rest
0
data fieldgoal;
set punt;
if color = 'Green' then code =1;
else if color in ('GreenRed','RedGreen') then code =2;
else if color in ('GreenYellow','YellowGreen') then code =3;
else if color in (‘___GreenREd’, ‘RedGreen__’) then code = 4;
else code = 0;
run;
Note that Anycolor can be up to 20 other colors, therefore making those
strings very different in spelling and in length. Does anyone have an idea
how I can code this fourth one completely?
thanks,
Datalover Cantcode.
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
-----------------------------------------
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and/or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.