BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ammarhm
Lapis Lazuli | Level 10

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

View solution in original post

6 REPLIES 6
ammarhm
Lapis Lazuli | Level 10

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 

art297
Opal | Level 21

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

ammarhm
Lapis Lazuli | Level 10

Thanks, it shoudnt matter as I have 

\s*

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

Any other suggesions please

 

art297
Opal | Level 21

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

 

Tom
Super User Tom
Super User

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.

ChrisNZ
Tourmaline | Level 20

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 6 replies
  • 1066 views
  • 0 likes
  • 4 in conversation