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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 546 views
  • 2 likes
  • 3 in conversation