Dear team
I have 10 variables ie Q1 to Q10 and each variable has same coding value ie Yes = 1, No = 2, Dk = 98 and NA = 99. My problem is that the "Yes" (code =1) answer can not repeated among the 10 variables. How can I control the repeating code?
Thank you.
Regards
Brti
Code should not repeated
Re: Code should not repeated
Hi Brti,
Can you have a single variable (I'm calling it QQ below) that repeats 10 times? If so, then you can do something like this:
Sherrell
Can you have a single variable (I'm calling it QQ below) that repeats 10 times? If so, then you can do something like this:
PROC QQ
if $=1 and count(REPEATING_REC where QQ=1) > 1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
If however you need to keep them as separate/single variables, then you'd have to hardcode the increasingly long blocks of logic; i.e.,if $=1 and count(REPEATING_REC where QQ=1) > 1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
PROC Q02
if Q01=1 and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
PROC Q03
if (Q01=1 or Q02=1) and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
PROC Q04
if (Q01=1 or Q02=1 or Q03=1) and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
Since you only have 10 variables I don't think it's worth the time to make a function for this.if Q01=1 and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
PROC Q03
if (Q01=1 or Q02=1) and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
PROC Q04
if (Q01=1 or Q02=1 or Q03=1) and $=1 then
errmsg ("Only one 'yes' response can be given for the Q1-Q10 variables");
endif;
Sherrell
-
- Posts: 49
- Joined: October 15th, 2020, 3:40 am
Re: Code should not repeated
Thank you so much Sherrell. It worked.