SAS Programming

DATA Step, Macro, Functions and more
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

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 7 replies
  • 1071 views
  • 2 likes
  • 4 in conversation