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

Hello,

 

I have a list of 15k respondents (each has a customer id), who have answered questions about the no. of pets they have (ranges 0 - as many pets they have). I have 6 variables (1 for no. of dogs, 2 for no. of cats, etc.): Q15_1 Q15_2 ... Q15_6

 

Irrespective of the type of pet and the no. of pets under each category, I need to find the no. of respondents with more than 1 pet.

 

For example, if respondent 23 has answered that he has 2 dogs (Q15_1) and 1 cat (Q15_2), and respondent 42 has answered that he has 2 cats (Q15_2) , they should both be regarded as respondents with more than 1 pet.

How can I do that in SAS? Is Proc Tabulate to be used for this? Any help is appreciated as I have never used it before.

 

Attached is sample data.

Regards,

MS

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a statement you can use within a DATA step.  It creates a variable that is 1 when the respondent has more than 1 pet, and 0 when the respondent has 0 or 1 pet.

multiple_pets = sum(of q15_1 - q15_16) > 1;

Presumably you can work with that to get any result that you have asked for.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Can you post some sample data please? Makes it much easier to provide a usable code answer

Astounding
PROC Star

Here's a statement you can use within a DATA step.  It creates a variable that is 1 when the respondent has more than 1 pet, and 0 when the respondent has 0 or 1 pet.

multiple_pets = sum(of q15_1 - q15_16) > 1;

Presumably you can work with that to get any result that you have asked for.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1396 views
  • 2 likes
  • 3 in conversation