Replacing a Character variable with part of another Character variable

sas

    Next

  • 1. Converting time to a format without ":" in proc export
    Hi, I've searched previous posts and using the following to export my data: PROC EXPORT DATA= GEVS.results_hist_main_view OUTFILE= "Z:\SAS\Results\Results_%sysfunc(today (),date9.)%sysfunc(time(),HHMM.).csv" DBMS=CSV REPLACE; run; Unfortunately in windows you can't have a ":" in the filename. Is there a function that will remove this? or is there a better time format to use? Thanks, Jer
  • 2. Per Subject Datasets
    Hi all, I work in the pharma sector and upto now have not had to create 'per patient' datasets, i.e one patient per dataset. However now I do..... I have a data called patlist in work containing all my patient numbers in a column called patient. I have 20 datasets at another libname, i need to produce a new data per patient in the format of dsname_patient, format example, my datasets is called DEM and my patient is called 1001001, the dataset should be called DEM_1001001 Now I want this to work automatically so i dont have to call the datasets and patients each time, ie. %perpat(dem,1001001), i dont want to have to do this, i want a macro to loop through the 20 datasets and reference the patlist. Any ideas ? Regards Colm
  • 3. AUTOEXE which can write something in program editor???
    Hi All, I am wondering if the following can happen. I am using AUTOEXE on my local machine to set the macro option and page size as well as line size for the reports. But i am wondering if we can use the autoexe in such a way that every time a new session start then it will automatically print some text in the program editor, i am thinking that if this is possible then i can get the macro variables with the %LET except there value which i will just fill at the start of that session. Like in my case i frequently use the account number (ACCNUM) and name (NAME) as macro variable in the code. So every time i start the SAS session i type %LET ACCNUM = 'XXXXXX'; %LET NAME = 'YYYY'; Now if the above is possible then in the start of the session i will get the statements like following in the editor, so that i will not need to write the %LET.... again and again. %LET ACCNUM = ; %LET NAME = ; Thanks in the advance Vikas

Replacing a Character variable with part of another Character variable

Postby SAS Student » Mon, 10 Dec 2007 07:24:13 GMT

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   Pennsylvania
Levittown, PA    19057


          Novice SAS user



Replacing a Character variable with part of another Character variable

Postby SAS Student » Mon, 10 Dec 2007 08:02:04 GMT

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





Replacing a Character variable with part of another Character variable

Postby SAS Student » Mon, 10 Dec 2007 08:20:54 GMT

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


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



Return to sas

 

Who is online

Users browsing this forum: No registered users and 77 guest