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

Hi all, 

suppose to have the following dataset:

data DB;
  input ID :$20. City :$20. School :$20. Parents :$20.;
cards;
0001 0   0   0
0001 1   1   1
0004 1   0   0
0004 0   0   1
0004 0   0   0
0005 0   1   1
0006 1   0   0
0006 1   1   1
0006 1   1   0
....
;

I'm trying to merge all the variables to get the following:

 

data DB1;
  input ID :$20. Index :$20.;
cards;
0001 0
0001 1
0004 1
0004 1
0004 0
0005 1
0006 1
0006 1
0006 1
....
;

The rule is: if there is at least one "1" in "City", "School", "Parents" then Index = 1 otherwise 0. I tried to use coalesce but it takes a lot of time because the variables to be collapsed are 10 but the rows are 30.000. Is there an alternative to do the job?

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Something like below should work.

data want;
  set have;
  index = whichc('1',city,school,parents) > 0;
run;

Bit weird that variables only containing zero and one are of type character with a length of $20

View solution in original post

2 REPLIES 2
AhmedAl_Attar
Rhodochrosite | Level 12

why not use this 

data DB(KEEP=ID index);
  input ID :$20. City :$20. School :$20. Parents :$20.;
  
  index = max(city,school,parents);
cards;
0001 0   0   0
0001 1   1   1
0004 1   0   0
0004 0   0   1
0004 0   0   0
0005 0   1   1
0006 1   0   0
0006 1   1   1
0006 1   1   0
....
;
run;
Patrick
Opal | Level 21

Something like below should work.

data want;
  set have;
  index = whichc('1',city,school,parents) > 0;
run;

Bit weird that variables only containing zero and one are of type character with a length of $20

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!
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
  • 373 views
  • 1 like
  • 3 in conversation