Similar Threads:
1.Replacing a Character variable with part of another Character
> -----Original Message-----
> From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On Behalf Of SAS
> Student
> Sent: Saturday, December 08, 2007 2:24 PM
> To: XXXX@XXXXX.COM
> 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 not match the city/state (6th observation),
> create a code that suggests either edits to the zipcode or city/state.
What do you mean by create a code? It would be helpful if you took the sample data from your email and showed us what you would like the end result to be.
>
> 2. If the Zipcode is invalid (1st observation) i need to replace its
> value with "???"
How do you know that a ZIPCODE is invalid? Because location is blank? If you write back to SAS-L and show us what you want to end up with, someone will surely be able to give you some useful help (maybe even me :-).
Dan
Daniel Nordlund
Bothell, WA USA
2.How to replace certain characters in a variable with '_'
Hi all,
I have dataset like following:
data temp;
length name $50.;
input name &;
cards;
lotrel(5/40 & 10/40)
lisinopril/HCTZ
vivell3-Dot
Sinemet CR
;
I want the output as follows:
lotrel_5_40_&_10_40
lisinopril_HCTZ
vivell3_Dot
Sinemet_CR
1) In the output if variable is made up of 2 or more words, I have to
replace the space ' ', '/' or hyphen '-' in the variable with
underscore '_' . e.g in case of 2nd, 3rd and 4th variable : '/','-'
and ' ' will be replaced by '_'.
2) Also if there is paranthesis, it should be replaced by '_'. Also
the space between paranthesis should be replaced by '_'.
I tried to use TRANSLATE function, but couldn't find the solution.
Please Help.
Regards,
Amar Mundankar.
3.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!
4.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
5.how to sort variable by character variable first then numeric
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: XXXX@XXXXX.COM ] On Behalf Of
Karen
Sent: Saturday, April 26, 2008 9:00 AM
To: XXXX@XXXXX.COM
Subject: 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!
6. transfer character variable to numeric variable( date)
7. Newbie, still :-(, SAS question convert numeric variable to character variable
8. Change character variable to num variable