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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.