Help using Base SAS procedures

how to find the location of the last char use index(-1)???

Reply
Regular Contributor
Posts: 241

how to find the location of the last char use index(-1)???

[ Edited ]

Hello all,

 

I want extract the number after the last '/', how to do it?

 

below is the character, I want '9245',:

 

'Kwstala/416544/95ewS661204/9245'

 

 

 

Thank you!

Super User
Super User
Posts: 7,039

Re: how to find the location of the last char use index(-1)???

Posted in reply to GeorgeSAS

Use SCAN() function with a index of -1.

want = scan('Kwstala/416544/95ewS661204/9245',-1,'/');
Regular Contributor
Posts: 241

Re: how to find the location of the last char use index(-1)???

Thank you!

 

and another question,how to get the location of the last '/'?

 

Thanks!

Respected Advisor
Posts: 3,156

Re: how to find the location of the last char use index(-1)???

Posted in reply to GeorgeSAS

You can use those PRX functions to get the target striong as well the postion:

data test;
	want_scan = scan('Kwstala/416544/95ewS661204/9245',-1,'/');
	ptn=prxparse('/(?<=\/)\d+$/');
	pos=prxmatch(ptn,'Kwstala/416544/95ewS661204/9245');
	want_prx=prxchange('s/(\S+)\/(\d+$)/\2/',-1,'Kwstala/416544/95ewS661204/9245');
run;
Super User
Posts: 10,018

Re: how to find the location of the last char use index(-1)???

Posted in reply to GeorgeSAS
data _null_;
	want_scan ='Kwstala/416544/95ewS661204/9245';
	pos=findc(want_scan,'/','b');
	put pos= ;
run;
Valued Guide
Posts: 2,177

Re: how to find the location of the last char use index(-1)???

Posted in reply to GeorgeSAS
Use CALL SCAN()
this will trll you the position and length of the selected "word".
For the last "word" try -1 in :
Call scan( big_string, -1, pos, len, '/' ) ;
Ask a Question
Discussion stats
  • 5 replies
  • 325 views
  • 0 likes
  • 5 in conversation