Page 1 of 1
Code should not repeated
Posted: November 5th, 2021, 11:50 am
by Arjun Brti
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
Re: Code should not repeated
Posted: November 5th, 2021, 1:46 pm
by sherrell
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:
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.,
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.
Sherrell
Re: Code should not repeated
Posted: November 6th, 2021, 12:04 pm
by Arjun Brti
Thank you so much Sherrell. It worked.