BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexxxxxxx
Pyrite | Level 9

Dear all,

 

How can I split the value when they are included in the ( ),[ ],{ },' '," ", or separated by blank but not other functions( especially, '.')?

 

Thanks ChrisNZ's code, I can split the value when they are included in the ( ),[ ],{ },' '," ", or separated by blank now. the code is 

data HAVE;
input NO NAME &:$100.;
infile datalines  missover;
datalines;
1 juice<BR>a@pple[footer] 
2 juice <BR> apple 
3 juice<BODY> 'apple' 
4 juice{BODY} apple 
5 [BR]juice appl'e
6 <figure> "juice" LTD 
run;

data WANT;
  set HAVE;
  length PAIR MATCH_PAIR MATCH_PAIRS $200 WORD $20;
  retain REGEX;
  array PAIRS [12] $1 _temporary_ ( '['  ']'  '{'  '}'  '<'  '>'  '"'  '"'  "'"  "'"  '('  ')' ) ;
  if _N_=1 then do;
    do I=1 to 12 by 2;
      MATCH_PAIR  = catt('\', PAIRS[I], '(.*)\', PAIRS[I+1]);
      MATCH_PAIRS = catx('|', MATCH_PAIRS, MATCH_PAIR);
    end;
    REGEX = prxparse(catt('s/', MATCH_PAIRS, '/ $1$2$3$4$5$6 /'));
  end;
  NAME1=prxchange(REGEX, -1, NAME);
  do I=1 to countw(NAME1,' ');
    WORD=scan(NAME1, I);
    output;
  end;
  keep NO WORD;
run;

However, I am facing a new problem during further processing, which is, the value is also separated by the periods.

for example, for the value 

7 M & L PROPERTY & ASS.PLC.
8 MMM L.T.D.F.
9 JJJ LTD.H

 

I get 

 

NONAMEWORDNAME1
7M & L PROPERTY & ASS.PLC.MM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.LM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.PROPERTYM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.ASSM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.PLCM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC. M & L PROPERTY & ASS.PLC.
8MMM L.T.D.F.MMMMMM L.T.D.F.
8MMM L.T.D.F.LMMM L.T.D.F.
9JJJ LTD.HJJJJJJ LTD.H
9JJJ LTD.HLTDJJJ LTD.H

  

However, I expect to get

NONAMEWORDNAME1
7M & L PROPERTY & ASS.PLC.MM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.LM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.PROPERTYM & L PROPERTY & ASS.PLC.
7M & L PROPERTY & ASS.PLC.ASS.PLC.M & L PROPERTY & ASS.PLC.
8MMM L.T.D.F.MMMMMM L.T.D.F.
8MMM L.T.D.F.L.T.D.FMMM L.T.D.F.
9JJJ LTD.HJJJJJJ LTD.H
9JJJ LTD.HLTD.HJJJ LTD.H

Could you please give me some suggestion about this?

thanks in advance.

data HAVE;
input NO NAME &:$100.;
infile datalines  missover;
datalines;
1 juice<BR>a@pple[footer] 
2 juice <BR> apple 
3 juice<BODY> 'apple' 
4 juice{BODY} apple 
5 [BR]juice appl'e
6 <figure> "juice" LTD 
7 M & L PROPERTY & ASS.PLC.
8 MMM L.T.D.F.
9 JJJ LTD.H
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

I replied and told you to use a space as the third augment of the scan function.

Did you try?

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

I replied and told you to use a space as the third augment of the scan function.

Did you try?

Alexxxxxxx
Pyrite | Level 9

Dear @ChrisNZ ,

 

could you please explain it for me? I am not understand 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 745 views
  • 0 likes
  • 2 in conversation