BookmarkSubscribeRSS Feed
smallembo
Calcite | Level 5

Hello,

 

I'm a relatively new SAS user so I'm not sure how to do this but it seems like it should be possible.

 

I have variables for all 50 states and want to split them into a new variable depending on whether or not they have expanded Medicaid coverage or not. Then, I want to be able to make the Medicaid variable into a binary 0/1 in order to run a diff-in-diff model. Is that possible? In my head it would look something like:

 

ACAyes = (Arizona, Arkansas, California);  

ACAno = (Alabama, Florida, Georgia);

 

Medicaid = 0;

if ACAyes = 1 then Medicaid = 1;

if ACAno = 1 then Medicaid = 0;

 

Thanks for your help!

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

So just to be clear, you have variables named Arizona, Arkansas, California and so on, correct? What do those variables contain?

smallembo
Calcite | Level 5

Yes, I should have clarified that! I created each variable with a state name from an original variable, _STATE, which coded each state according to a number. So, now that you point that out, I should probably go back to the original variable to make the Medicaid variable. Perhaps something like:

 

Medicaid = 0;

if _STATE = (1, 2, 3) then Medicaid = 1;

if _STATE = (4, 5, 6) then Medicaid = 0;

Shmuel
Garnet | Level 18

Coding: if _STATE = (1, 2, 3) is wrong sas syntax. what you mean is:

 

if _STATE in (1  2  3) then Medicaid = 1; else Medicaid = 0;

assuming that (1 2 3) are the only those with Medicaid = 1;

smallembo
Calcite | Level 5

Ah, thank you for pointing out my syntax. As far as the if/else statement, there are a few states and territories in the original _STATE variable that I don’t want to be in either grouping and want them to be disregarded for the diff-in-diff model. How would you suggest I code the statement so that the states I want to disregard don’t wind up in the model? Would it work to sssign them to another number?

PaigeMiller
Diamond | Level 26

As far as the if/else statement, there are a few states and territories in the original _STATE variable that I don’t want to be in either grouping and want them to be disregarded for the diff-in-diff model.

 

In your data step or PROC, if for example you don't want states 5 and 27 in the analysis, then

 

where state not in (5,27);

 

--
Paige Miller
smallembo
Calcite | Level 5

Thank you! Can I ask one more question? I have tried this code:

 

data newCOMBO where _STATE not in (2 22 23 49 51 66 72 78);
set COMBO;
Medicaid = 0;
if _STATE = (4 5 6 8 9 10 11 15 17 18 19 21 24 25 26 27 30 31 32 33 34 35 36 38 39 41 42 44 50 53 54) then Medicaid = 1;

run;

 

But keep running into these errors:

 

WARNING: The data set WORK.NEWCOMBO may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: The data set WORK.WHERE may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK.WHERE was not replaced because this step was stopped.
WARNING: The data set WORK._STATE may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK._STATE was not replaced because this step was stopped.
WARNING: The data set WORK.NOT may be incomplete. When this step was stopped there were 0
observations and 160 variables.
WARNING: Data set WORK.NOT was not replaced because this step was stopped.

 

 

Everything works fine up until this point so I'm thinking this step is definitely written wrong. 

PaigeMiller
Diamond | Level 26
if _STATE in (4 5 6 8 9 10 11 15 17 18 19 21 24 25 26 27 
    30 31 32 33 34 35 36 38 39 41 42 44 50 53 54) then Medicaid = 1;
--
Paige Miller

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
  • 8 replies
  • 683 views
  • 0 likes
  • 4 in conversation