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
As @Tom said, the messages are pretty clear (except it is variables P and L which are the culprits) .
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
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
Thanks, it shoudnt matter as I have
\s*
I did try your code thoiugh and it is the same problem
Any other suggesions please
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
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.
As @Tom said, the messages are pretty clear (except it is variables P and L which are the culprits) .
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.