Read your post multiple times, but still i am unable to grasp the rules that should be applied. So please explain them. Also explain, why you want to use "anyspace".
I think you want to do something like the example below, using Regular Expressions
What the example is doing is looking for a comma, followed by any number and combination of numerics and spaces, followed by another comma. It then extracts that value and converts it into a numeric.
Be warned this will also pick up values like ", 1 2 3 ," which will then probably return missing values.
What's not clear from your post is why the output has
/* Using Perl Regular Expressions in the DATA Step */
/* https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1vz3ljudbd756n19502acxazevk.htm */
data ss;
input details $33.;
cards;
anam kusuma,3 id 2018, svcp
b bhavana, tirupati, 2018, 011
gracy, tirupati
indu priya, sas, 22, nellore
;
run;
data want ;
retain regExpID ;
if _n_=1 then do ;
regExpID=PRXPARSE('/,[0-9 ]*,/') ;
end ;
set ss ;
prxmatch=prxmatch(regExpID,details) ;
if pexmatch then do ;
prxposn=prxposn(regExpID,0,details) ;
number=inputn(substr(prxposn,2,length(prxposn)-2),"8.") ;
end ;
else
number=0 ;
put details= ;
put prxmatch = ;
put prxposn = ;
put number= ;
put "-------" ;
run ;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.