BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dennis_oz
Quartz | Level 8

 

Hi all,

Appreciate some help on this .

 

Thanks in advance.

 

data a;
input word1 $ & 200.;
datalines;
101 Capital Region R 000s
101 Capital Region R Uwgt
101 Capital Region R Index
102 Central Coast R Unwgt
102 Central Coast R 000s
102 Central Coast R Vert percent
;
run;


want 
101 Capital Region
101 Capital Region
101 Capital Region 
102 Central Coast
102 Central Coast
102 Central Coast
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
where=max(find(word1,' R '),find(word1,' M '));
--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

So what are the rules for doing this truncation of the text? Is it always truncated after the third word, or before the "R", or do you always want the first 18 columns?

--
Paige Miller
dennis_oz
Quartz | Level 8

Hi, Yes it is before the "R".

Thank you .

ballardw
Super User

One way:

data want;
   set a;
   word1 = substr(word1,1,findw(word1,'R')-1);
run;

Not the only by any means.

 

PaigeMiller
Diamond | Level 26
data want;
    set a;
    where=find(word1,' R ');
    word1=substr(word1,1,where-1);
    drop where;
run;
--
Paige Miller
dennis_oz
Quartz | Level 8

sorry slight update to requirement , suppose the data is as below , i.e  a combination of R and M

 

data a;
input word1 $ & 200.;
datalines;

102 Central Coast R 000s
103 Capital Region M 000s

;
run;
want ----- 102 Central Coast 103 Capital Region
 

 

andreas_lds
Jade | Level 19

Which letter will be added to the separator list with the next update of the requirements?

PaigeMiller
Diamond | Level 26
where=max(find(word1,' R '),find(word1,' M '));
--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 552 views
  • 2 likes
  • 4 in conversation