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

Hi I need help in extracting only policies whereby there is a value greater than or equals 1 from either contents/ motor/ home columns..if all the values from  contents/ motor/ home columns are 0, then delete the entire row..

 

see below code for data have

data have;
input policy_no risk contents motor home cycle;
datalines;
1 1 0 1 0 0
2 0 0 0 0 1
3 0 1 1 2 1
4 1 0 0 0 0
5 1 0 0 0 1
6 0 1 1 2 0
;

 

Data Want

policy_no   risk  contents  motor   home   cycle

1                1        0             1          0           0

3                0        1             1          2           1   

6                0        1             1          2           0

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do this

 

data have;
input policy_no risk contents motor home cycle;
datalines;
1 1 0 1 0 0
2 0 0 0 0 1
3 0 1 1 2 1
4 1 0 0 0 0
5 1 0 0 0 1
6 0 1 1 2 0
;

data want;
   set have;
   if sum(contents, motor, home);
run;

 

Result:

 

policy_no risk contents motor home cycle 
1         1    0        1     0    0 
3         0    1        1     2    1 
6         0    1        1     2    0 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Do this

 

data have;
input policy_no risk contents motor home cycle;
datalines;
1 1 0 1 0 0
2 0 0 0 0 1
3 0 1 1 2 1
4 1 0 0 0 0
5 1 0 0 0 1
6 0 1 1 2 0
;

data want;
   set have;
   if sum(contents, motor, home);
run;

 

Result:

 

policy_no risk contents motor home cycle 
1         1    0        1     0    0 
3         0    1        1     2    1 
6         0    1        1     2    0 
Solly7
Pyrite | Level 9
Thanks a lot..its working fine
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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