DATA Step, Macro, Functions and more

Extract a substring based on eccurrence of character

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Extract a substring based on eccurrence of character

HI,

 

I have a set of data with percentages.

TotalC is a character variable.

 

TotalC

222,98

1,0.3

2,45

13,45

 

 

I need to extract only the part of string before , (210,1,2,13).

 

I need a numeric variable total:

 

Total

210

1

2

13

 

Please advise.

 

Thanks,

Archana


Accepted Solutions
Solution
‎08-31-2016 02:42 PM
Respected Advisor
Posts: 4,923

Re: Extract a substring based on eccurrence of character

Posted in reply to ArchanaSudhir

total = input(scan(totalc,1,","), best.);

PG

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Extract a substring based on eccurrence of character

Posted in reply to ArchanaSudhir

Where does the 210 come in? Did you mean the part before the comma:

 

A character variable could be:

 

 

Newvariable = scan(TotalC,1,',');

in a data step.

 

If you need more than before only the first comma then you will need to provide rules.

 

If there is no part before the comma what should the returned value be?

Solution
‎08-31-2016 02:42 PM
Respected Advisor
Posts: 4,923

Re: Extract a substring based on eccurrence of character

Posted in reply to ArchanaSudhir

total = input(scan(totalc,1,","), best.);

PG
☑ This topic is solved.

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

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