BookmarkSubscribeRSS Feed
pjones98
Calcite | Level 5

I am using the HRS for a project and would like to create an 'insurance' variable pulling values from the individual insurance indicators that have overlap with each other.

 

I have medicaid (yes/no) as 'medicaid'

combine spouse (yes/no) or personal employe plan (yes/no) or any gov plan (yes/no) as 'other'

private insurance is a counted variable of how many plans they have, where I would like to do as >=1 means they have private insurance

 

i've tried doing

if medicaid=1 then insurance=1;

else if employee=1 or spouse=1 or gov=1 then insurance=2;

else if private>=1 then insurance=3;

else insurance=.;

 

but since people can have more than one type of insurance, none of the frequencies are correct after medicaid.

 

Is there a way to properly code this?

 

2 REPLIES 2
andreas_lds
Jade | Level 19

I would be easier to help you, if you could share some data (as data step using datalines) and show the expected output.

ballardw
Super User

@pjones98 wrote:

I am using the HRS for a project and would like to create an 'insurance' variable pulling values from the individual insurance indicators that have overlap with each other.

 

I have medicaid (yes/no) as 'medicaid'

combine spouse (yes/no) or personal employe plan (yes/no) or any gov plan (yes/no) as 'other'

private insurance is a counted variable of how many plans they have, where I would like to do as >=1 means they have private insurance

 

i've tried doing

if medicaid=1 then insurance=1;

else if employee=1 or spouse=1 or gov=1 then insurance=2;

else if private>=1 then insurance=3;

else insurance=.;

 

but since people can have more than one type of insurance, none of the frequencies are correct after medicaid.

 

Is there a way to properly code this?

 


Is your intent that if they have the private insurance >= 1 regardless of the employee, spouse or gov values to set the resulting variable insurance to 3? If so then change the order of the if/then/else so the private is compared before the employee/spouse/gov variables.

 

But agree that example data and desired result is needed. The example only needs to include some identifier, for discussion of specific respondents, and the values of the variables to consider and what the result looks like.

 

This code will simulate, at least as I understand your data at this time, examples of pretty much all the types of cases that could exist of the various variables shown and the results of your code. You can tell us which values of ID are incorrect and why.

 

data have;
   retain id;
   do medicaid=.,0,1;
   do employee=.,0,1;
   do spouse  =.,0,1;
   do gov     =.,0,1;
   do private = .,0,1,2;
      id+1;
      if medicaid=1 then insurance=1;
      else if employee=1 or spouse=1 or gov=1 then insurance=2;
      else if private>=1 then insurance=3;
      else insurance=.;
      output;
   end;
   end;
   end;
   end;
   end;
run;

 

If this is not like your data then you need to provide an example.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 486 views
  • 0 likes
  • 3 in conversation