I am trying to create a variable called Federal_Insurance which, contains the variables, Medicaid, Medicare, Workmanscomp, Tricare. Each of those insurance types is its own variable. Is there any way I can create variable "Federal" without saying if MEdicaid=1 and Medicare=1 and so on.....
data have
studynum Medicaid Medicaid
1 1 0
2 0 1
3 1 0
What is the logic behind the creation of Federal_Insurance?
If MEdicaid=1 and Medicare=1 and Workmanscomp=1 and Tricare=1 then what? 🙂
Federal_Insurance = compress(Medicaid||Medicare||Workmanscomp||Tricare);
if you have 1 and 0's this will give you:
1000 = medicaid
0100 = medicare
1100 = Medicaid and meidicare
and so on;
1. Create an array for the list of variables
2. Use WHICHN() to get the index of the variable with a 1
3. Use VNAME () to get the name of the column
With this approach it doesn't matter how many programTypes you have and you don't need any IF statements. If the variable names are not exactly what you want, you may need to recode them.
array programTypes(*) medicaid medicare WCB Tricare;
index = whichn(1, of programTypes(*));
Program_Type = vname(programTypes(index));
@stancemcgraw wrote:
I am trying to create a variable called Federal_Insurance which, contains the variables, Medicaid, Medicare, Workmanscomp, Tricare. Each of those insurance types is its own variable. Is there any way I can create variable "Federal" without saying if MEdicaid=1 and Medicare=1 and so on.....
data have
studynum Medicaid Medicaid
1 1 0
2 0 1
3 1 0
A single transpose step:
proc transpose data=have out=want(where=(col1)) name=federal;
by studynum;
var medicaid -- tricare;
run;
Indian Health Service also perhaps?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.