Problem with Perl regular expression

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 135
Accepted Solution

Problem with Perl regular expression

Ok i am literally stuck and dont understand this:

I am running a code with Perl regular expression:

 

 

 

Data want;
set have;
o=prxparse('/(number:) \s*\d+/i');
start=1;stop=length(nr);
call prxnext(o,start,stop,nr,p,l);
NR=compress(substr(nr,p,l),,'kd');
  drop o start stop p l;
run;

The contents of nr looks like this:

 

NR NUMBER:         123456

 

 

This is returning the following error:

 

750  Data Want;
751  set Have;
752  o=prxparse('/(number:) \s*\d+/i');
753   start=1;stop=length(nr); l=1;
754   call prxnext(o,start,stop,nr,p,l);
           -------
           731
WARNING 731-185: Argument #5 is a character variable, while a numeric variable must be passed to
                 the PRXNEXT subroutine call in order for the variable to be updated.

754!  call prxnext(o,start,stop,nr,p,l);
           -------
           731
WARNING 731-185: Argument #6 is a character variable, while a numeric variable must be passed to
                 the PRXNEXT subroutine call in order for the variable to be updated.

755    *NR=compress(substr(nr,p,l),,'kd');
756  NR=substr(nr,p,l);
757    drop o start stop p l;
758  run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      753:30
NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      754:32   754:34   756:15   756:17
NOTE: Invalid second argument to function SUBSTR at line 756 column 4.

Could anyone please advice me on this

Thanks

 


Accepted Solutions
Solution
2 weeks ago
Trusted Advisor
Posts: 1,510

Re: Problem with Perl regular expression

As @Tom said, the messages are pretty clear  (except it is variables P and L which are the culprits) .

View solution in original post


All Replies
Frequent Contributor
Posts: 135

Re: Problem with Perl regular expression

Just a further explanation

i cant use the following 

NR=compress(nr,,'kd');

There are other numbers in the nr column before the text 'nr number' that I want to exclude

Thanks for your help 

Esteemed Advisor
Posts: 7,295

Re: Problem with Perl regular expression

Difficult to say without seeing your input data, but my guess is that you are inadvertently requiring an extra space. Try the following:

Data want;
  set have;
  o=prxparse('/(number:)\s*\d+/i');
  start=1;stop=length(nr);
  call prxnext(o,start,stop,nr,p,l);
  NR=compress(substr(nr,p,l),,'kd');
  drop o start stop p l;
run;

Art, CEO, AnalystFinder.com

Frequent Contributor
Posts: 135

Re: Problem with Perl regular expression

Thanks, it shoudnt matter as I have 

\s*

I did try your code thoiugh and it is the same problem

Any other suggesions please

 

Esteemed Advisor
Posts: 7,295

Re: Problem with Perl regular expression

Post some examples of your nr field.

 

I posted my response based on:

/* fails with */
data have;
  informat nr $80.;
  input id nr &;
  cards;
1  number: 6
2  number:5
3  number: 12
;

Data want;
set have;
o=prxparse('/(number:) \s*\d+/i');
start=1;stop=length(nr);
call prxnext(o,start,stop,nr,p,l);
NR=compress(substr(nr,p,l),,'kd');
  drop o start stop p l;
run;

/* but would work with */

data have;
  informat nr $80.;
  input id nr &;
  cards;
1  number: 6
2  number:5
3  number: 12
;

Data want;
set have;
o=prxparse('/(number:)\s*\d+/i');
start=1;stop=length(nr);
call prxnext(o,start,stop,nr,p,l);
NR=compress(substr(nr,p,l),,'kd');
  drop o start stop p l;
run;

 

Art, CEO, AnalystFinder.com

 

Super User
Super User
Posts: 6,361

Re: Problem with Perl regular expression

The notes and error messages seems pretty clear to me.

Your code is expecting NR to be a character variable, but in your source dataset it is a number.

Your code is expecting P to be a numeric variable, but in your source dataset it is a character string.

Solution
2 weeks ago
Trusted Advisor
Posts: 1,510

Re: Problem with Perl regular expression

As @Tom said, the messages are pretty clear  (except it is variables P and L which are the culprits) .

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 113 views
  • 0 likes
  • 4 in conversation