Dear SAS community,
I would like to ask you to help me solve the following problem.
I have the following data set:
Id Subid T1 Tx Both
1 1 1 0 (1)
1 2 1 0 (1)
1 3 0 1 (1)
1 4 0 1 (1)
2 1 0 1 (0)
2 2 0 1 (0)
2 3 0 1 (0)
There are some Id's with subid's listed. At the same time, these have 2 dummy variables "T1" and "Tx", which never have the same value. This means that if T1=0, then Tx=1 and vice versa.
The question is: how can I create a variable "Both" that checks whether both dummies within a single Id have a value of 1?
Like if T1=1 and Tx=1 wihtin Id=1 then Both=1
Many thanks in advance.
It appears that you want a value of BOTH for every record.
proc sql;
create table want as select *,
case when max(t1)=1 and max(tx)=1 then 1 else 0 end as both
from have
group by id;
quit;
Which brings up the question — why are you creating dummy variables and working with them in the first place? Most SAS statistical procedures do not require you to create dummy variables; the dummy variables will be created behind the scenes for you (SAS is pretty smart) so you don't have to struggle with this. What will the usage of these dummy variables be?
Many thanks for the answer. Dummie was perhaps not the right term, but "flag" was more appropriate. I need this step when sorting data to highlight the relevant entries.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.