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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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