DATA Step, Macro, Functions and more

scan function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

scan function

data test;

string='abc_234_knm_dfjkdhf_dfdkf';

run;

 

i want ouput like

 

output_col = knm_dfjkdhf_dfdkf

 

can some one help on this 


Accepted Solutions
Solution
‎04-24-2018 01:13 PM
Super User
Posts: 6,543

Re: scan function

I would use:

 

output_col = substr(string, length(scan(string, 1, '_')) + length(scan(string, 2, '_')) + 3);

 

I'm sure those familiar with parsing functions could find something elegant.

View solution in original post


All Replies
PROC Star
Posts: 1,357

Re: scan function

[ Edited ]

output_col =scan(string,-1,'_');

Occasional Contributor
Posts: 16

Re: scan function

Posted in reply to novinosrin

it wil come only "dfdkf"

Solution
‎04-24-2018 01:13 PM
Super User
Posts: 6,543

Re: scan function

I would use:

 

output_col = substr(string, length(scan(string, 1, '_')) + length(scan(string, 2, '_')) + 3);

 

I'm sure those familiar with parsing functions could find something elegant.

Occasional Contributor
Posts: 16

Re: scan function

Posted in reply to Astounding

THANK YOU SO MUCH !!

Super User
Posts: 10,626

Re: scan function

data test;

string='abc_234_knm_dfjkdhf_dfdkf';
x=substr(string,findc(string,'1234567890','b')+1);
put x=;
run;
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 139 views
  • 0 likes
  • 4 in conversation