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
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
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
Anytime 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.