BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Takumi
Calcite | Level 5
obsPARKSTYRESTABACRES
1ArchesUT197173000
2CanyonlandsUT1964338000
3Capitol ReefUT1971242000
4ZionUT1919147000
5Bryce CanyonUT192436000

Hello. I was told to remove the word "Canyon" in "PARK".

So this is what I did:

DATA UT;

Infile 'C:\SAS\natlpark.txt';
PARK $ 1- 20 ST $ 21-22 YRESTAB 25-28 ACRES COMMA10.;

If st ^= "UT" then delete;

Acres = round(acres,1000);

t = indexw(park, 'Canyon')';

If t then PARK = substr(park,1,t-1);

run;

proc print data=UT;

run;

obsPARKSTYRESTABACRESt
1ArchesUT1971730000
2CanyonlandsUT19643380000
3Capitol ReefUT19712420000
4ZionUT19191470000
5Bryce UT1924360007

As you can see I successfully removed the word Canyon from "Bryce Canyon", but from observation 2 the word "Canyonlands" still carries with it the word "Canyon" at the front. I tried using the split(), scan(), but it gives me weird answers. How can I remove the word Canyon in Canyonlands??

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Tranwrd would be one option:

NEW_PARK = tranwrd(upcase(PARK),"CANYON",""));

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

indexW searches for words perhaps you want to seach at the string level.  Look for a function that searches in that way.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Tranwrd would be one option:

NEW_PARK = tranwrd(upcase(PARK),"CANYON",""));

Takumi
Calcite | Level 5

Ohhh amazin'! Thanks

pradeepalankar
Obsidian | Level 7

or u may try this

park=transtrn(park,'Canyon','');

Xianhua_zeng
Fluorite | Level 6

a complex method

park=prxchange('s/(Canyon)//i',-1,park);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 681 views
  • 7 likes
  • 5 in conversation