BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
metallon
Pyrite | Level 9

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

1 REPLY 1
data_null__
Jade | Level 19

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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