BookmarkSubscribeRSS Feed
Zakharkou
Calcite | Level 5

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.

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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?

 

--
Paige Miller
Zakharkou
Calcite | Level 5

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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