## creating a dummy variable based on a list of elements

Solved
Super Contributor
Posts: 459

# creating a dummy variable based on a list of elements

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:

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

thank you!

Accepted Solutions
Solution
‎05-17-2015 01:10 AM
Super User
Posts: 10,699

## Re: creating a dummy variable based on a list of elements

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;

All Replies
Solution
‎05-17-2015 01:10 AM
Super User
Posts: 10,699

## Re: creating a dummy variable based on a list of elements

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;

Super Contributor
Posts: 459

## Re: creating a dummy variable based on a list of elements

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!

🔒 This topic is solved and locked.