Code should not repeated

Discussions about CSEntry
Post Reply
Arjun Brti
Posts: 49
Joined: October 15th, 2020, 3:40 am

Code should not repeated

Post 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
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: Code should not repeated

Post 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
Arjun Brti
Posts: 49
Joined: October 15th, 2020, 3:40 am

Re: Code should not repeated

Post by Arjun Brti »

Thank you so much Sherrell. It worked.
Post Reply