Substring with condition

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Substring with condition

Hi everyone,

 

I have the following data with company name and TIC code.

CompanyTIC
ACAVR.1
BCAB.3
C4330B

 

Now with TIC code that have character '.' , I would like to extract only characters before the '.'

For example, TIC code CAVR.1 will be sub-stringed to CAVR

 

The output looks like this:

CompanyTIC
ACAVR
BCAB
C4330B

 

Can anyone help me with this, please? Any idea would be much appreciated


Accepted Solutions
Solution
‎01-02-2018 06:50 AM
Super User
Posts: 3,777

Re: Substring with condition

Posted in reply to trungcva112
TIC = scan(TIC, 1, '.');

The SCAN function gets the first word in the string where the word boundary is a dot.

View solution in original post


All Replies
Solution
‎01-02-2018 06:50 AM
Super User
Posts: 3,777

Re: Substring with condition

Posted in reply to trungcva112
TIC = scan(TIC, 1, '.');

The SCAN function gets the first word in the string where the word boundary is a dot.

PROC Star
Posts: 1,190

Re: Substring with condition

Posted in reply to trungcva112
data have;
input Company$ TIC$;
datalines;
A	CAVR.1
B	CAB.3
C	4330B
;

data want;
   set have;
   tic=scan(TIC, 1, '.');
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 266 views
  • 2 likes
  • 3 in conversation