Help using Base SAS procedures

Grouping String Variable s

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Grouping String Variable s

Hopefully there is an easy solution to this problem...

Question: What type of insurance do you have? (check all that apply)

Private insurance provided by employer q99r1

  Insurance provider through family member employer  q99r2

  Insurance purchased directly from insurance company  q99r3

......

I would like to group these insurance types into smaller groups, however when running the following code, I do not get true values.

data work.pwl_spss; /****message 10****/ 

set work.pwl_spss;

if q99r1 = 1 then  q99m = 1 ;/***Private***/

if q99r2 = 1 then  q99m=1;

if q99r3 = 1 then  q99m=1;

if q99r9 = 1 then  q99m=1;

if q99r4 = 1 then  q99m=1;

if q99r7 = 1 then  q99m=2; /**2=Medicare***/

if q99r8 = 1 then  q99m=2;

if q99r10 = 1 then  q99m=3; /****3=Medicaid***/

if q99r11 = 1 then  q99m=4; /***4=Other***/

if q99r12 = 1 then  q99m=4;

if q99r13 = 1 then  q99m=4;

if q99r6 = 1 then  q99m=4;

if q99r14 = 1 then  q99m=6;/***6=Not Sure***/

run;

For example, when adding together q99r1- q99r4, I get 562, but when running this code I get 472.

Thanks!


Accepted Solutions
Solution
‎07-24-2014 01:20 PM
Super User
Posts: 11,343

Re: Grouping String Variable s

Post an example subset of your data and expected result. I'm not sure why you keep talking about these sums as they are irrelevant for recoding multiple variables into one due to the multiple response nature of the data.

And if you are recoding before cleaning the data, since you say you have values of 2 that should be 0/1 then you may have other issues.

What value do you want q99m to be when all of q99r1, q99r6,q99r7 and q99r10 are equal to 1? You are quite likely to have responses that in multiple of you target range, especially Private and Other (betting that your other includes Champus/Tricare military and/or Indian health services or similar) and not impossible to have overlaps with Private and Medicare. Less likely but you may even have overlaps with medicaid.

Your existing code in my example question is going to assign 4 but your looking at the private only variables woud expect you to have a private assignment.

You have to determine a priority which will mask some of your results.

I would usually create 5 dichotomous variables for the target groups so that I would be able to analyze within respondents that had any private insurance as well as any medicare or "other".

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Grouping String Variable s

This is because you are counting multiple responses once.

e.g

q99r1 q99r2 q99r3 q99r9   q99m

1          1        1         1          1

1          0        0         0          1

so frequency for

q99m=2

while total frequency for q99r1 +  q99r2 + q99r3 + q99r9 is 5

Super User
Posts: 10,041

Re: Grouping String Variable s

data work.pwl_spss; /****message 10****/

set work.pwl_spss;

if q99r1 = 1 then  q99m = 1 ;/***Private***/

else if q99r2 = 1 then  q99m=1;

else if q99r3 = 1 then  q99m=1;

else if q99r9 = 1 then  q99m=1;

else if q99r4 = 1 then  q99m=1;

else if q99r7 = 1 then  q99m=2; /**2=Medicare***/

else if q99r8 = 1 then  q99m=2;

else if q99r10 = 1 then  q99m=3; /****3=Medicaid***/

else if q99r11 = 1 then  q99m=4; /***4=Other***/

else if q99r12 = 1 then  q99m=4;

else if q99r13 = 1 then  q99m=4;

else if q99r6 = 1 then  q99m=4;

else if q99r14 = 1 then  q99m=6;/***6=Not Sure***/

run;   



??????????

Contributor
Posts: 26

Re: Grouping String Variable s

Hi KSharp,

I have tried that method of code as well, but it is still not giving me the true value, I am surely lost in this.

When adding,  q99r1 q99r2 q99r3 q99r4 and q99r9 i get 562. When using the code mentioned in my first comment, I get 472. When using the code mentioned by stat@sas I get 1=546,  2=8 (no clue where the

'2' came from as the repsonse options are 1 for 0 for no).  When using the code mentioned by Ksharp, the output is 554.  Thanks for everyone's help thus far, very much appreciated!

Solution
‎07-24-2014 01:20 PM
Super User
Posts: 11,343

Re: Grouping String Variable s

Post an example subset of your data and expected result. I'm not sure why you keep talking about these sums as they are irrelevant for recoding multiple variables into one due to the multiple response nature of the data.

And if you are recoding before cleaning the data, since you say you have values of 2 that should be 0/1 then you may have other issues.

What value do you want q99m to be when all of q99r1, q99r6,q99r7 and q99r10 are equal to 1? You are quite likely to have responses that in multiple of you target range, especially Private and Other (betting that your other includes Champus/Tricare military and/or Indian health services or similar) and not impossible to have overlaps with Private and Medicare. Less likely but you may even have overlaps with medicaid.

Your existing code in my example question is going to assign 4 but your looking at the private only variables woud expect you to have a private assignment.

You have to determine a priority which will mask some of your results.

I would usually create 5 dichotomous variables for the target groups so that I would be able to analyze within respondents that had any private insurance as well as any medicare or "other".

Contributor
Posts: 26

Re: Grouping String Variable s

Hope this helps in explaining my issue, and thank you again for your conintued help.

When I run q99r1, q99r2,q99r3, q99r3 and q99r9 individually, their respecitve counts are 260, 234, 33, 13, and 22 which adds up to 562.  When I have tried running the aforemention codes, neither has given my the value of 562.

When either q99r1, q99r2,q99r3, q99r3 and q99r9 equals '1(yes)', I want the sum of the dummy variable which groups these varaibles to be 562.

IDq99r1 q99r2 q99r3
1yesyesno
2noyesno
3noyesyes
4no nono
5yesnono
Super User
Posts: 11,343

Re: Grouping String Variable s

But what do you want as a result in the case I mentioned? You have a single outcome variable Q99M which also gets assigned when variables other than q99r1-4 and 9. As long as you have multiple variables in addition to those that set q99m then you are going to have inconsistency. If you want a varaible assigned just for that group you can use something like:

Q99g1 = (max( of q99r1-q99r4, q99r9) = 1);

and additional group variables for the other combinations.

However if you still have values of 2 when you say they should be 1 and 0 then you've still got other problems.

Contributor
Posts: 26

Re: Grouping String Variable s

Thank you ballrdw! That response seems to have worked for the grouping every insurance group except "Private" where 8 are still missing, assuming those are the 8 listed as "2". Went through the dataset and all responses are either 'yes' 'no' so I'll try to figure this out on my own.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 354 views
  • 7 likes
  • 4 in conversation