Prxparse

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Prxparse

 

 

I have this type of data:

 

125628,59000,.,.,.,.

.,50000,.,.,.,.

 

using 

 

 prx=prxparse("s/.,[., ]*/, /");

I get 

 

 

 

12562, 5900, , , , .

, 5000, , , , .

 

 

I would like to have 

 

125628,59000

50000


Accepted Solutions
Solution
‎03-01-2018 09:54 AM
Super User
Super User
Posts: 9,606

Re: Prxparse

Well, perl I can't help you with, however its a simple thing in Base SAS code to do:

data have;
  tmp="125628,59000,.,.,.,."; output;
  tmp=".,50000,.,.,.,."; output;
run;

data want (drop=i);
  length tmp2 $200;
  set have;
  do i=1 to countw(tmp,",");
    if scan(tmp,i,",") ne "." then tmp2=catx(',',tmp2,scan(tmp,i,","));
  end;
run;
  

View solution in original post


All Replies
Solution
‎03-01-2018 09:54 AM
Super User
Super User
Posts: 9,606

Re: Prxparse

Well, perl I can't help you with, however its a simple thing in Base SAS code to do:

data have;
  tmp="125628,59000,.,.,.,."; output;
  tmp=".,50000,.,.,.,."; output;
run;

data want (drop=i);
  length tmp2 $200;
  set have;
  do i=1 to countw(tmp,",");
    if scan(tmp,i,",") ne "." then tmp2=catx(',',tmp2,scan(tmp,i,","));
  end;
run;
  
Valued Guide
Posts: 582

Re: Prxparse

not fully tested:

data want;
   set have;
   tmp2 = transtrn(tmp, ',.', ' ');
   tmp2 = strip(transtrn(tmp2, '.,', ' '));
run;
PROC Star
Posts: 2,375

Re: Prxparse

With a RegEx:

data t; 
  STR=prxchange('s/,\./ /', -1, '125628,59000,.,.,.,.');
  putlog STR=;
run;

STR=125628,59000

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 145 views
  • 0 likes
  • 4 in conversation