DATA Step, Macro, Functions and more

regex from R to SAS

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 133
Accepted Solution

regex from R to SAS

Hi,

 

I have to migrate some old R code to sas and found the following:

 

datarow$varibale[grep(".*a.*",datarow$Original),] <- "new column"

 

I dont quite get what its doing, guessing it takes everything that starts with .a and put it in a new varialbe Iwonder if someone can help me translating it into sas.

 

thanks

 


Accepted Solutions
Solution
‎01-22-2016 05:14 AM
Respected Advisor
Posts: 3,777

Re: regex from R to SAS

I think it matches any string that contains an "a".  At least that's what my limited testing shows.

4043  data _null_;
4044     input line $20.;
4045     if _n_ eq 1 then rx=prxparse("/.*a.*/");
4046     retain rx;
4047     match = prxmatch(rx,strip(line));
4048     put (_all_)(=);
4049     cards;

line=hello rx=1 match=0
line=helloah rx=1 match=1
line=zzz rx=1 match=0
line=  rx=1 match=0
line=ahhello rx=1 match=1
line=678ab rx=1 match=1
line=a rx=1 match=1
line=ta rx=1 match=1
line=u rx=1 match=0

View solution in original post


All Replies
Solution
‎01-22-2016 05:14 AM
Respected Advisor
Posts: 3,777

Re: regex from R to SAS

I think it matches any string that contains an "a".  At least that's what my limited testing shows.

4043  data _null_;
4044     input line $20.;
4045     if _n_ eq 1 then rx=prxparse("/.*a.*/");
4046     retain rx;
4047     match = prxmatch(rx,strip(line));
4048     put (_all_)(=);
4049     cards;

line=hello rx=1 match=0
line=helloah rx=1 match=1
line=zzz rx=1 match=0
line=  rx=1 match=0
line=ahhello rx=1 match=1
line=678ab rx=1 match=1
line=a rx=1 match=1
line=ta rx=1 match=1
line=u rx=1 match=0
☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 161 views
  • 1 like
  • 2 in conversation