SAS PRXPARSE用法检索字符串匹配模式的长度

时间:2015-10-22 21:28:28

标签: regex sas

我必须从ADDITIONAL_DETAILS字段检索X轴和Y轴pos,其长度超过300个字节。

在此字符串中的某处,我将位置详细信息视为RETLOCID=2312.4892。 我想在PERL REGEX中使用SAS

问题:我可以通过调用prxsubstr(MATCH_PATTERN1, ADDITIONAL_DETAILS, postn1,length1)将起始位置输入postn1;但是长度总是以8为单位返回,即使它不止于此。

TRANSACTION_ID = substrn(ADDITIONAL_DETAILS, postn1, length1);当我将长度限制为8时,这并没有给我正确的价值。任何帮助都表示赞赏。以下是代码:

DATA WORK.LOCATION;
  INFILE DATALINES; 
  INPUT ADDITIONAL_DETAILS $50.;
  datalines;
afdsf RFTXNID=121.5435 xx 
fdsg RFTXNID=7821.5487 xx fdsg
gfdgf
  ;
RUN;
data WORK.POSITION;
  set WORK.POSITION;
  if _N_ = 1 then do; 
    MATCH_PATTERN1 = PRXPARSE("/(RETLOCID=)/");
    MATCH_PATTERN2 = PRXPARSE("/([0-9]{1,}\.[0-9]{1,})/");
  end;
  retain MATCH_PATTERN1 MATCH_PATTERN2;

  call prxsubstr(MATCH_PATTERN1, ADDITIONAL_DETAILS, postn1,length1);
  call prxsubstr(MATCH_PATTERN2, ADDITIONAL_DETAILS, postn2,length2);

  if postn1 > 0 and not missing(ADDITIONAL_DETAILS) then 
    TRANSACTION_ID = substrn(ADDITIONAL_DETAILS, postn1 + 8, length1);
RUN;

data work.POSITION;
  set work.POSITION;
  drop MATCH_PATTERN1 postn1 length1;
run;

我需要拉121.5435和7821.5487

1 个答案:

答案 0 :(得分:2)

试试这个:

DATA WORK.LOCATION;
INPUT ADDITIONAL_DETAILS $50.;
string=prxchange('s/[a-z=_]+//i',-1,ADDITIONAL_DETAILS);
datalines;
afdsf RFTXNID=121.5435 xx 
fdsg RFTXNID=7821.5487 xx fdsg
DISTR_QUOTE=66.92
gfdgf
;
run;

或者

DATA WORK.LOCATION;
INPUT ADDITIONAL_DETAILS $50.;
length string $20.;
if prxmatch('/\=/',ADDITIONAL_DETAILS)=0 then string='';
else string=prxchange('s/.*(?<=\=)([^a-z]+).*/$1/i',-1,ADDITIONAL_DETAILS);
datalines;
afdsf RFTXNID=121.5435 xx 
fdsg RFTXNID=7821.5487 xx fdsg
gfdgf
DISTR_QUOTE=66.92 
;
proc print;
run;