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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2178 views
  • 0 likes
  • 4 in conversation