f



Replacing a Character variable with part of another Character variable #2

Good evening all,

 I have a small problem that I need to solve and would appreciate any
help you offer.
 I created the below table using some raw data. I created the
Location
variable using the
 ZIPCITY function. As you can see, in the last observation the City
"Harrisbu" does not match the city under Location "Levittown" while
for the first observation the Location is left blank because the
zipcode is invalid. I need a simple code that does the following:


1.If they zipcode does not match the city/state (6th observation),
create a code that suggests either edits to the zipcode or city/
state.
One way is is to compare the "City" variable with the first part
(city)
of the "Location" varaible and asking SAS to replace the former
with the latter if they don't match. Needless to say, I don't now
how to do that...

2. If the Zipcode is invalid (1st observation) i need to replace its
value with "???"

This is just part of the dataset so I need something that is global.
Also, please keep it as simple as possible so that I can understand
what you did. Thanks a lot !

  Obs    PatientName           City     StateName
location           zipcode

   1    Sonya Larson      Buffalo      New
York                                   10068
   2    Peter Simpson     Isabel        Kansas          Isabel,
KS              67065
   3    Kip Holfser            Lansing    Michigan        Lansing,
MI            48910
   4    Chan Rong         Lithonia       Georgia          Lithonia,
GA          30058
   5    Mary Peters        Greenbay    Wisconsin      Green Bay,
WI      54311
   6    Randy Nguyen        Harrisbu   Pennsylvania   Levittown,
PA       19057




0
o.ibrahim0 (10)
12/8/2007 11:02:04 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

0 Replies
698 Views

Similar Articles

[PageSpeed] 27

Reply:

Similar Artilces:

Replacing a Character variable with part of another Character variable
Good evening all, I have a small problem that I need to solve and would appreciate any help you offer. I created the below table using some raw data. I created the Location variable using the ZIPCITY function. As you can see, in the last observation the City "Harrisbu" does not match the city under Location "Levittown" while for the first observation the Location is left blank because the zipcode is invalid. I need a simple code that does the following: 1.If they zipcode does not match the city/state (6th observation), create a code that suggests either edits to the zipcode or city/state. 2. If the Zipcode is invalid (1st observation) i need to replace its value with "???" This is just part of the dataset so I need something that is global. Also, please keep it as simple as possible so that I can understand what you did. Thanks a lot ! Obs PatientName StreetAddress City StateName location zipcode 1 Sonya Larson 10054 Plum Tree Rd Buffalo New York 10068 2 Peter Simpson 605 Glendover Dr Isabel Kansas Isabel, KS 67065 3 Kip Holfser 902 West Blvd Lansing Michigan Lansing, MI 48910 4 Chan Rong 3052 East Bank Way Lithonia Georgia Lithonia, GA 30058 5 Mary Peters 10036 Lake View Dr Greenbay Wisconsin Green Bay, WI 54311 6 Randy Nguyen 100 49th Street Harrisbu Pennsylvani...

Replacing a Character variable with part of another Character variable #3
Good evening all, I have a small problem that I need to solve and would appreciate any help you offer. I created the below table using some raw data. I created the Location variable using the ZIPCITY function. As you can see, in the last observation the City "Harrisbu" does not match the city under Location "Levittown" while for the first observation the Location is left blank because the zipcode is invalid. I need a simple code that does the following: 1.If they zipcode does not match the city/state (6th observation), create a code that suggests either edits to the zipcode or city/ state. One way is is to compare the "City" variable with the first part (city part) of the "Location" varaible and asking SAS to replace the former with the latter if they don't match (e.g replace Harrisbu with Levittown). Needless to say, I don't now how to do that... 2. If the Zipcode is invalid (1st observation) i need to replace its value with "???" This is just part of the dataset so I need something that is global. Also, please keep it as simple as possible so that I can understand what you did. Thanks a lot ! City zipcode State StateName location Buffalo 10068 NY New York Isabel 67065 KS Kansas Isabel, KS Lansing 48910 MI Michigan Lansing, MI Lithonia 30058 GA Georgia Lithonia, GA Greenbay 54311 WI Wisconsin Green Bay, WI Harrisbu 19057 PA Pennsylvania Levittown, PA ...

Re: Replacing a Character variable with part of another Character #2
On Sat, 8 Dec 2007 14:58:19 -0800, Daniel Nordlund <res90sx5@VERIZON.NET> wrote: >> -----Original Message----- >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of SAS >> Student >> Sent: Saturday, December 08, 2007 2:24 PM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: Replacing a Character variable with part of another Character variable >> >> Good evening all, >> >> I have a small problem that I need to solve and would appreciate any >> help you offer. >> I created the below table using some raw data. I created the Location >> variable using the >> ZIPCITY function. As you can see, in the last observation the City >> "Harrisbu" does not match the city under Location "Levittown" while >> for the first observation the Location is left blank because the >> zipcode is invalid. > >It will be a lot easier for people to help you if you provide a self-contained program that generates your sample data, rather than making them try to extract data from a poorly formatted email (everything is wrapping haphazardly at my end of the email). http://www.puzha.com/sasbook/sas%20examples.html#_Toc145244126 > >That being said, is this just a toy problem or is this a real problem you are trying to solve. I ask, because ZIP codes are not geographical regions, but rather mail delivery routes. There are many places where the zipcode &quo...

Re: Replacing a Character variable with part of another Character
> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of SAS > Student > Sent: Saturday, December 08, 2007 2:24 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Replacing a Character variable with part of another Character variable > > Good evening all, > > I have a small problem that I need to solve and would appreciate any > help you offer. > I created the below table using some raw data. I created the Location > variable using the > ZIPCITY function. As you can see, in the last observation the City > "Harrisbu" does not match the city under Location "Levittown" while > for the first observation the Location is left blank because the > zipcode is invalid. It will be a lot easier for people to help you if you provide a self-contained program that generates your sample data, rather than making them try to extract data from a poorly formatted email (everything is wrapping haphazardly at my end of the email). That being said, is this just a toy problem or is this a real problem you are trying to solve. I ask, because ZIP codes are not geographical regions, but rather mail delivery routes. There are many places where the zipcode "location" does not match the town. In fact, sometimes even the state won't match. So I'm not convinced you should be editing anything. >I need a simple code that does the following: > > 1.If they zipcode does n...

Re: How to add character in between the character variable #2
informat rsabcd_c $3.; rsabcd_c=3D substr(rsabcd,1,1) || '/' || substr(rsabcd,2,1); -Mary ----- Original Message -----=20 From: vrajeshrawal@gmail.com=20 To: SAS-L@LISTSERV.UGA.EDU=20 Sent: Wednesday, March 04, 2009 6:15 AM Subject: How to add character in between the character variable Hello, I have a character variable named rsABCD with the VALUE "GG". I wantr to make it "G/G". How to do it....I ...

Re: SAS 9.2: PROC MEANS with Character Variables #2
that makes not much sense: VAR should be reserved for numeric variables to calculate statistics. Simply leave that statement off and leave only output out=x; in. Gerhard On Wed, 3 Sep 2008 08:33:35 -0700, Paige Miller <paige.miller@KODAK.COM> wrote: >On Sep 3, 10:47 am, jcl...@HILLTOP.UMBC.EDU (Jack Clark) wrote: > >> I think the doc is talking about all the variables in the data set, not >> the variables on the VAR statement. > >No. This doesn't work on data sets where all the variables are >character. > >> When I need to see the distribution or get a count of observations with >> missing vs. non-missing values for numeric or character variables, I use >> a format and the FREQ procedure. > >I understand that there are workarounds involving PROC FREQ. I have >many different character variables, and all I want to do is find out >if there are non-missing values for them. It is so much simpler to >program in PROC MEANS as > >proc means; > var _character_; > output out=_a_ n=; >run; > >There is no similar capability in PROC FREQ. > >Thus, I am very much hoping that the SAS Docs are correct and you can >include character variables in the VAR statement. > >-- >Paige Miller >paige\dot\miller \at\ kodak\dot\com ...

how to sort variable by character variable first then numeric variable
Hi, who knows if we can use SAS to sort the variables by character variable first and then numeric variable. Such as: The original order is: StudentID Score Gender Address I want to sort it as StudentID Gender Address Score Any hint? Thanks very much! Check these sites for guidance on using proc sort and using proc sql. Look for the by statement in proc sort and the order by statement in proc sql. Good Luck. AB3BO Don http://www.ats.ucla.edu/STAT/sas/modules/sort.htm http://www2.sas.com/proceedings/sugi27/p191-27.pdf On Apr 26, 12:00 pm, Karen <irain...@gmail.com> wrote: > Hi, > > who knows if we can use SAS to sort the variables by character > variable first and then numeric variable. > > Such as: > The original order is: > StudentID Score Gender Address > > I want to sort it as > > StudentID Gender Address Score > > Any hint? > > Thanks very much! ...

Re: Change character variable to num variable #2
"How can I change this character variable "2007/02" ($7.) to a numeric one?" I would go for the yymms. informat but this informat does not exist only the format. Instead I would suggest to remove the / thanks to the compress function and they apply a yymmn6. informat. data one; x_char=compress('2007/02','/'); x_num=input(x_char,yymmn6.); format x_num yymms.; put x_char= x_num=; run; source: http://v8doc.sas.com/sashtml/lrcon/zenid-63.htm ...

Re: how to change the character variable to numerical variable? #2
Irene, I think you are trying to do the following: libname exercise "k:\art"; data exercise.dataset1; input sampid $; cards; 1 1 2 2 3 3 ; data exercise.dataset1; set exercise.dataset1; sampid_num=input(sampid,best12.); drop sampid; rename sampid_num=sampid; run; However, I'd strongly recommend NOT overwriting your original dataset! Art ---------- On Sun, 2 Mar 2008 07:50:51 -0800, irenelj23@gmail.com <irenelj23@GMAIL.COM> wrote: >There is a variable in dataset1 in the exercise library. I tried to >change the type of one of the variables-ID from character to >numerical. Is this the right way to do? >I first created a new variable id_num and then dropped the old >variable ID which is character, then I changed the name of the >numerical id_num to the original name ID. > >data exercise.dataset1; >set exercise.dataset1; >id_num=input(ID,best12.); >drop sampid; >rename sampid_num=sampid; > >Thanks for your help! ...

Re: How to transfer character variables into numeric variables by #2
Would the following do what you want? data chen; input a $ b $ c $; cards; 1 2 3 a 4 5 6 b 7 8 c d ; run; data chen; set chen; array XXX[*] _character_; array YYY[3]; do kk=1 to DIM(XXX); YYY[kk]=input(XXX[kk],1.); end; run; Art --------- On Sun, 24 Jul 2005 04:57:04 -0400, subscribe sas-L Chen, Chiu-Chen <angelina.aml@YAHOO.COM.TW> wrote: >I have some mixed columns in an Excel data. So I read all variables into >SAS as character variables. Now I want to transfer all character variables >to numerical variables, but how should I write the program´┐ŻHI wrote ...

Re: how to sort variable by character variable first then numeric #2
Hi Karen, There are many variations but here are a couple. data sample; StudentID='A1'; Score=78; Gender='M'; Address='123 Cherry Tree Lane'; output; StudentID='B2'; Score=79; Gender='F'; Address='456 Cherry Tree Lane'; output; run; We can order the columns specifically, AND we can order the columns by CHARACTER then NUMERIC. Below are examples of both. There are several ways to order the column in specific order: * SQL order as you list them ; proc sql; create table result1 as select StudentID, Gender, Address, Score from sample ; quit; * datastep compiler order them in ; * the order they are incurred. ; * i.e. LENGTH found before SET. ; data result2; length StudentID $2 Gender $1 Address $20 Score 8 ; set sample; run; Here is one way to order by CHAR then NUM. * ordering by character then numeric ; data result3; set sample(keep=_character_); set sample(keep=_numeric_); run; Hope this is helpful. Mark Terjeson Senior Programmer Analyst Investment Management & Research Russell Investments Russell Investments Global Leaders in Multi-Manager Investing -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Karen Sent: Saturday, April 26, 2008 9:00 AM To: SAS-L@LISTSERV.UGA.EDU Subject:...

Replacing code based on static variables to variable variables. #2
Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack type lines and the number of Single type lines. We use it to create a web page that allows us to split a garment delivery over multiple dates and and to specify the number and size of garments in a pack and the number and size of individual garments in the delivery. 3 of each has been enough until now. However we are finding new customers that want it spread over as many as 5 to 8 of each type pack and single. Everything is stored in an array $RPack. Easy to do as i new there ...

Calling a variable by a character variable
It is better using an example. I would call a variable by keyword and I would see his value on my screen. More or less: CHARACTER :: var_name myvar1 = 5 myvar2 = 7 ....... myvar1000 = 8 Write(*,*) 'variable name' Read(*,*) var_name I would type 'myvar1' (or mayvar2, myvar3,...) and then I would see the respective variable's value on my screen. I have a lot of variables, therefore a solution like If var_name='myvar1' write(*,*) myvar1 etc.. could be not convenient. How can I do? Thanks and I am sorry I was not clear Allamarein wrote: >...

How to add character in between the character variable
Hello, I have a character variable named rsABCD with the VALUE "GG". I wantr to make it "G/G". How to do it....I Hello, I have a character variable named rsABCD with the VALUE "GG". I want to make it "G/G". How to do it....I Infact I have hundreds of variables in the dataset similar to rsABCD and I want All of them to appear as "G/G" or "A/T" ...

SAS 9.2: PROC MEANS with Character Variables
I simply want to count how many observations of a character variable have a non-missing value. So I look at the documentation for PROC MEANS, and under the VAR statement, the documentation says "When all variables are character variables, PROC MEANS produces a simple count of observations". So PROC MEANS does work on character variables! Sounds exactly what I am looking for! But I can't get it to work. PROC MEANS DATA=abc; VAR name; RUN: produces the following error: ERROR: Variable name in list does not match type prescribed for this list. Please tell me how to make this work. (Or please tell me the docs are wrong) Thanks -- Paige Miller paige\dot\miller \at\ kodak\dot\com ...

Re: changing length and format of all character variables in SAS #2
You could use a view, most easily , a data step view, like: data sasuser.shrink_widths /view= sasuser.shrink_widths ; set &your_spss_data_transferred ; format _character_ $11. ; run; Then viewing sasuser.shrink_widths will provide a quick/narrow view which you can use as a base. Where you need to see wider columns, the viewtable window options allow you to apply a wider format to any column. Perhaps you prefer a more-permanent effect. proc datasets nolist ; modify &your_spss_data_transferred ; format _character_ $11. ; run; quit; ...

Re: Change SAS Variable type from Numeric to Character #2
Don , When using the put function one does not need the left or right functions simply use the buit in format tools of the put function: put( acct_nbr_1 , 9. -L ) ; put( acct_nbr_1 , 9. -R ) ; put( acct_nbr_1 , 9. -C ) ; Toby Dunn From: Don <dmorgan@ROCKETMAIL.COM> Reply-To: Don <dmorgan@ROCKETMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Change SAS Variable type from Numeric to Character Date: Tue, 18 Apr 2006 11:40:34 -0700 Would the left(put(acct_nbr_1,9.) ) ; right(put(acct_nbr_1,9.)); Compress(put(acct_nbr_1,9.)," ");...

Re: SAS 9.2: PROC MEANS with Character Variables
Paige, I think the doc is talking about all the variables in the data set, not the variables on the VAR statement. When I need to see the distribution or get a count of observations with missing vs. non-missing values for numeric or character variables, I use a format and the FREQ procedure. * create format for Missing/Present ; Proc format; Value $ mp " " = "Missing" Other = "Present" ; Value mpn . = "Missing" Other = "Present" ; Run; title1 'Frequencies for Numeric Variables'; Proc freq data = test; Tables num_var1 / missing; Format num_var1 mpn.; Run; title1 'Frequencies for Character Variables'; Proc freq data = test; Tables char_var1 / missing; Format char_var1 $mp.; Run; Jack Clark Research Analyst phone: 410-455-6256 fax: 410-455-6850 jclark@hilltop.umbc.edu University of Maryland, Baltimore County Sondheim Hall, 3rd Floor 1000 Hilltop Circle Baltimore, MD 21250 Confidentiality Notice: This e-mail may contain information that is legally privileged and that is intended only for the use of the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying of this e-mail, distribution, or action taken in reliance on the contents of this e-mail and/or documents attributed to this e-mail is strictly prohibited. If you have received this information in error, plea...

Re: Searching for partial text in character variables in SAS #2
There are also the PERL regular expression functions. But you will have to wait for the late sleeping "regEXperts" to wake up and load up on caffeine. ...

Re: SAS 9.2: PROC MEANS with Character Variables #5
On 9/3/08, Paige Miller <paige.miller@kodak.com> wrote: > On Sep 3, 11:48 am, iebup...@GMAIL.COM ("./ ADD NAME=Data _null_,") > wrote: > > I think PROC FREQ NLEVELS will produce an adequate summary of the > > information you seek. > > > > ods select nlevels; > > proc freq data=sashelp.class(keep=_char_) nlevels; > > run; > > ods select all; > > This appears to solve my problem. Thanks. > > I'd still like to know what SAS had in mind when they said, referring > to the VAR statement, you could put character variables (plural) in > the VAR statement. Something this I think... proc summary missing data=sashelp.shoes; class _char_; ways 1; output out=work.oneWays; run; proc print; run; Although, I think NLEVELS is more appropriate for you based on what you said you wanted to know. > > -- > Paige Miller > paige\dot\miller \at\ kodak\dot\com > ...

Re: SAS 9.2: PROC MEANS with Character Variables #4
I think PROC FREQ NLEVELS will produce an adequate summary of the information you seek. ods select nlevels; proc freq data=sashelp.class(keep=_char_) nlevels; run; ods select all; On 9/3/08, Paige Miller <paige.miller@kodak.com> wrote: > On Sep 3, 10:47 am, jcl...@HILLTOP.UMBC.EDU (Jack Clark) wrote: > > > I think the doc is talking about all the variables in the data set, not > > the variables on the VAR statement. > > No. This doesn't work on data sets where all the variables are > character. > > > When I need to see the distribution or get a count of observations with > > missing vs. non-missing values for numeric or character variables, I use > > a format and the FREQ procedure. > > I understand that there are workarounds involving PROC FREQ. I have > many different character variables, and all I want to do is find out > if there are non-missing values for them. It is so much simpler to > program in PROC MEANS as > > proc means; > var _character_; > output out=_a_ n=; > run; > > There is no similar capability in PROC FREQ. > > Thus, I am very much hoping that the SAS Docs are correct and you can > include character variables in the VAR statement. > > -- > Paige Miller > paige\dot\miller \at\ kodak\dot\com > On Sep 3, 11:48=A0am, iebup...@GMAIL.COM ("./ ADD NAME=3DData _null_,") wrote: > I think PROC FREQ NLEVELS will produce an ad...

Re: SAS 9.2: PROC MEANS with Character Variables #3
try it with proc summary (or means) data=abc (where=(name ne " ")); output out=x; run; In dataset x you find in _freq_ the number. Gerhard On Wed, 3 Sep 2008 07:40:34 -0700, Paige Miller <paige.miller@KODAK.COM> wrote: >I simply want to count how many observations of a character variable >have a non-missing value. > >So I look at the documentation for PROC MEANS, and under the VAR >statement, the documentation says "When all variables are character >variables, PROC MEANS produces a simple count of observations". So >PROC MEANS does work on character variables! Sounds exactly what I am >looking for! > >But I can't get it to work. > >PROC MEANS DATA=abc; > VAR name; >RUN: > >produces the following error: >ERROR: Variable name in list does not match type prescribed for this >list. > >Please tell me how to make this work. (Or please tell me the docs are >wrong) > >Thanks > >-- >Paige Miller >paige\dot\miller \at\ kodak\dot\com ...

Re: SAS 9.2: PROC MEANS with Character Variables #6
On Wed, 3 Sep 2008 14:09:42 -0700, Reeza <fkhurshed@HOTMAIL.COM> wrote: >On Sep 3, 12:26 pm, Paige Miller <paige.mil...@kodak.com> wrote: >> On Sep 3, 11:48 am, iebup...@GMAIL.COM ("./ ADD NAME=Data _null_,") >> wrote: >> >> > I think PROC FREQ NLEVELS will produce an adequate summary of the >> > information you seek. >> >> > ods select nlevels; >> > proc freq data=sashelp.class(keep=_char_) nlevels; >> > run; >> > ods select all; >> >> This appears to solve my problem. Thanks. >> >> I'd still like to know what SAS had in mind when they said, referring >> to the VAR statement, you could put character variables (plural) in >> the VAR statement. >> >> -- >> Paige Miller >> paige\dot\miller \at\ kodak\dot\com > >The full statement is: >If you omit the VAR statement, then PROC MEANS analyzes all numeric >variables that are not listed in the other statements. When all >variables are character variables, PROC MEANS produces a simple count >of observations. Moreover, this paragraph is under the heading "Default", indicating that it pertains to the procedure's behavior when there are is no VAR declaration. > >Which is pretty much what it does. The two statements are related. >And yes, it doesn't indicate that it ignores it when there are numeric >variables or that v...

Change character variable to num variable
Hi, all How can I change this character variable "2007/02" ($7.) to a numeric one? Thanks Data _Null_ ; OldDate = '2007/02' ; NewDate = MDY( InPut( Scan( OldDate , 2 , '/' ) , 8. ) , 1 , InPut( Scan( OldDate , 1 , '/' ) , 8. ) ) ; Put OldDate= NewDate= Date9. ; Run Toby Dunn If anything simply cannot go wrong, it will anyway. Murphys Law #2. The buddy system is essential to your survival; it gives the enemy somebody else to shoot at. Murphys Law # Tell a man there are 300 billion stars in the universe and he'll b...

Web resources about - Replacing a Character variable with part of another Character variable #2 - comp.soft-sys.sas

Facebook Tests Replacing Keyword Ad Targeting With Broad Category Targeting
Facebook is testing a major functionality change for its self-serve performance ad tool that would replace the specific Like keyword targeting ...

Replacing a Pebble Smartwatch screen - YouTube
I got a broken Pebble from a friend, and fixed it with a dremel, some epoxy, and a replacement screen. Total cost of $30.

School apologises for taking cane off blind boy and replacing it with pool noodle
A primary school has apologised for taking away the cane of an eight-year-old blind boy and replacing it swimming pool noddle as a form of punishment. ...

Manly Sea Eagles coach Trent Barrett undaunted about replacing Geoff Toovey
Three days into his tenure as Manly coach, Trent Barrett's only concern was to take the club forward not the emotion that surrounded the axing ...

Replacing China's broken economic gauge
As Chinese growth shifts away from its reliance on heavy industry, we need a new index to the track the ups and downs of the economy.


Apache Software Foundation unveils Hadoop 2, replacing MapReduce with YARN
The Apache Software Foundation unveiled its latest release of its open source data processing program, Hadoop 2. It runs multiple applications ...

No talk of replacing Bill Shorten as Labor leader: Anthony Albanese
Labor frontbencher Anthony Albanese says he's not interested in taking over the leadership, and the party remains united behind Bill Shorten. ...

AMD appoints Lisa Su as first female CEO, replacing Rory Read
AMD has appointed Lisa Su chief executive officer to replace Rory Read, swapping an executive who has stabilised the second-biggest chipmaker's ...

A case of one bad government replacing another
THERE is a widening gap between the sort of government a Tony Abbott-led Coalition will need to become to steer the nation successfully in the ...

Resources last updated: 3/17/2016 3:30:10 PM