hi,
suppose that I have the folllowing table:
text |
---|
The banks and financial companies |
The bankers association |
First bank of England |
financial banking institutions |
If either the element "banks" or "financial" is present in an entry, then the new dummy variable =1, else 0.
So the table should be like this:
text | Header 2 |
---|---|
The banks and financial companies | 1 |
The bankers association | 0 |
First bank of England | 0 |
financial banking institutions | 1 |
thank you!
data have;
input text & $50.;
cards;
The banks and financial companies
The bankers association
First bank of England
financial banking institutions
;
run;
data want;
set have;
if prxmatch('/\bbanks\b|\bfinancial\b/i',text) then dummy=1;
else dummy=0;
run;
data have;
input text & $50.;
cards;
The banks and financial companies
The bankers association
First bank of England
financial banking institutions
;
run;
data want;
set have;
if prxmatch('/\bbanks\b|\bfinancial\b/i',text) then dummy=1;
else dummy=0;
run;
thanks Xia, your posts are very helpful, (as well as the posts of the other users)!
I actually tried to do this myself and even experimented with prxmatch, but even the smallest syntax inaccuracy can make the whole code not work (or work in an unintended way ...)
Thanks again!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.