hi,
suppose I have the following table:
| role |
|---|
| CEO/CFO |
| CEO since 1987 |
| President/CEO/Treasurer |
| Independent Director |
| First Independent In 2 Years |
I want to create 2 new variables CEO_dummy and Independent_dummy. If for example the word CEO is present for an entry in the Role column, then the new variable CEO_dummy will have a value of 1, and 0 otherwise.
The same thing for Independent.
So the new table should look like this:
| role | CEO_dummy | Independent_dummy |
|---|---|---|
| CEO/CFO | 1 | 0 |
| CEO since 1987 | 1 | 0 |
| President/CEO/Treasurer | 1 | 1 |
| Independent Director | 0 | 1 |
| First Independent In 2 Years | 0 | 1 |
Thank you!
If you're searching for WORDS you need the proper function.

Suppose dataset name is dataset1
data dataset1;
set dataset1;
if find(role,'CEO','i') > 0 then CEO_dummy=1;
else Independent_dummy=0;
run;
This will solve the problem.
Addition to the above code .This code will resolve your problem for missing dummy variables.
data dataset1;
IF FIND('role','ceo','i')>0 THEN DO;
ceo_DUMMY=1;
INDEPENDENT_DUMMY=0;
END;
ELSE IF(FIND(role','ceo','i')=0) THEN DO;
ceo_DUMMY=0;
INDEPENDENT_DUMMY=1;
END;
run;
Your test output doesn't work. The third line has 1 in both results, but I don't see the word independant in the string?
Its a simple task however:
data want;
set have;
if index(lowcase(role),"ceo") > 0 then ceo_dummy=1;
else ceo_dummy=0;
if index(lowcase(role),"independent") > 0 then independent=1;
else independent=0;
run;
you may use this also:
data want;
set have;
CEO_dummy=IFN(index(upcase(role),'CEO'),1,0);
INDEPENDENT_dummy=IFN(index(upcase(role),'INDEPENDENT'),1,0);
run;
via sql:
proc sql;
create table want as
select role,
case when index(upcase(role),'CEO') then 1 else 0 end as CEO_dummy,
case when index(upcase(role),'INDEPENDENT') then 1 else 0 end as INDEPENDENT_dummy
from have;
quit;
If you're searching for WORDS you need the proper function.

Thanks, now I even realize the importance of Independently alliaceous!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.