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
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?
Hi, Yes it is before the "R".
Thank you .
One way:
data want; set a; word1 = substr(word1,1,findw(word1,'R')-1); run;
Not the only by any means.
data want;
set a;
where=find(word1,' R ');
word1=substr(word1,1,where-1);
drop where;
run;
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
Which letter will be added to the separator list with the next update of the requirements?
where=max(find(word1,' R '),find(word1,' M '));
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.