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

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:

textHeader 2
The banks and financial companies1
The bankers association0
First bank of England0
financial banking institutions1

thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

2 REPLIES 2
Ksharp
Super User

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;

ilikesas
Barite | Level 11

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!

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 connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 804 views
  • 0 likes
  • 2 in conversation