Help using Base SAS procedures

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

Reply
Regular Contributor
Posts: 212

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: 6,502

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

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

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

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,124

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

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: 9,691

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

data _null_;
	want_scan ='Kwstala/416544/95ewS661204/9245';
	pos=findc(want_scan,'/','b');
	put pos= ;
run;
Valued Guide
Posts: 2,175

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

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
  • 324 views
  • 0 likes
  • 5 in conversation