BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
trevand
Obsidian | Level 7

I have 20 variables and need to create an indicator that equals to 1 if one of the variables equals to A10 and the other 19 are empty. I have no idea how I would do it. Here is a data example with 5 variables:

 

VAR_1 VAR_2 VAR_3 VAR_4 VAR_5 DUMMY
A10 B10       0
A10         1
  B10 C10     0
A10 B10 C10     0
A10       D10 0
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if cmiss(of var_1-var_20)=19 and whichc('A10',of var_1-var_20)>0 then dummy=1;
    else dummy=0;
run;

 

 

It may be that you are making your programming work difficult by creating a wide data set; in many cases creating a long data set with the same data is a lot easier to handle and program. Why? Because most SAS Procs are designed to work with long data sets. I urge you to explain the background of this problem, and what you are planning to do next once you have this dummy variable, so that we can advise further. We need to understand the big picture, not the tiny details of how to create the dummy variable.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if cmiss(of var_1-var_20)=19 and whichc('A10',of var_1-var_20)>0 then dummy=1;
    else dummy=0;
run;

 

 

It may be that you are making your programming work difficult by creating a wide data set; in many cases creating a long data set with the same data is a lot easier to handle and program. Why? Because most SAS Procs are designed to work with long data sets. I urge you to explain the background of this problem, and what you are planning to do next once you have this dummy variable, so that we can advise further. We need to understand the big picture, not the tiny details of how to create the dummy variable.

--
Paige Miller
quickbluefish
Barite | Level 11

Alternatively:


dummy=(catx(',',of var:)='A10');

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 952 views
  • 2 likes
  • 3 in conversation