Hello experts,
Can someone tell me why the metacharacter \n is not working for the program belw
data a;
infile cards truncover;
length a $1;
input a $150.;
cards;
a
b
run;
data b;
set a;
e=prxmatch("/a\nb",a);
run;
Thanks
You have two obs not one , therefore PRX can't work on that situation .
HI ksharp,
can an you use \n to read new line in regular expression?
Hello,
Maybe this is what you are looking for:
data a;
a="103 Pennsylvania Ave. NW,";output;
a="Washington, DC 20216" ;output;
a="NY, DC 20216" ;output;
run;
data b;
set a;
b=prxparse("/103 Pennsylvania Ave\. NW|Washington, DC 20216/");
e= prxmatch(b,a);
run;
Check also the following link:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295977.htm
I have modified the program to make it more simple.
No.
If you have organized your dataset so that each line is on a separate observation you cannot use the SAS perl regular expression functions to operate across observations.
To check if you ever have the condition that "B" follows "A" in your data set perhaps you want to use LAG() function?
Here is a trivial example .
data want ;
input a $ ;
if a='B' and lag(a)='A' then found=1;
else found=0;
CARDS;
A
B
C
D
B
A
C
A
B
run;
In this case only the second and the final observation will have FOUND set to 1.
I would not use SAS for this type of parsing of a structured text file. Use awk: it is designed for this. Awk is a small program available on almost all operating systems. It is part of unix. If you do not have awk, use perl, which is bigger and more complex. After you have used awk to reorganise the data, read it into SAS. You should be able to run the awk from SAS, or use a command script to run both. I use this method frequently.
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.
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.