BookmarkSubscribeRSS Feed
SAS93
Quartz | Level 8

I don't recall having learned this "directly", but experience seems to point that it does. I just wanted to clarification on it. 

 

I have been using SAS to group a series of Y/N survey response variables into a single categorical variable for defining a respondent's insurance status.

 

I've been doing this for a single set of years (example: Set 1 = 2012 - 2014, Set 2 = 2015 - 2017). Each set has mostly the same variable names, except Set 1 has a few additional variables that Set 2 doesn't have, and one that is named differently. 

 

So:

/* Set 1 */

If work in (1) or comp in (1) then insurance = 1; *work or partner's work;

If medic in (1) or gov in (1) then insurance = 2; *Medicaid or other government-funded;

if other in (1) then insurance = 3; *other;

if none in (1) then insurance = 4; *none;

 

/* Set 2 */

If work4 in (1) or hcech in (1) then insurance = 1; *work or healthcare exchange program;

If medic in (1)  then insurance = 2; *Medicaid or other government-funded;

if other in (1) then insurance = 3; *other;

if none in (1) then insurance = 4; *none;

 

I ask because--when run the Set 1 and Set 2 datasets separately with their respective codes, I always get the same numbers for Set 2 regardless of running separately or combined with Set 1, but Set 1 is always different depending on how I run it. I just wanted to confirm that this "overwriting" is what was happening. 

3 REPLIES 3
SAS93
Quartz | Level 8

Data instatus;

Set ins.set1 ins.set2;

 

* Set 1 = 2012 - 2014;

* Set 2 = 2015 - 2017;

* YY_STAT  = survey year; char var, YYYY format;

 

/* Status for Set 1 */

If work in (1) or comp in (1) then insurance = 1; *work or partner's work;

If medic in (1) or gov in (1) then insurance = 2; *Medicaid or other government-funded;

if other in (1) then insurance = 3; *other;

if none in (1) then insurance = 4; *none;

 

/* Set 2 */

If work4 in (1) or hcech in (1) then insurance = 1; *work or HSA program;

If medic in (1)  then insurance = 2; *Medicaid or other government-funded;

if other in (1) then insurance = 3; *other;

if none in (1) then insurance = 4; *none;

 

Run;

Kurt_Bremser
Super User

The variable insurance exists only once in the PDV, so all those statements will have an effect on it.

If medic and other are both 1, then insurance = 3 will "overwrite" insurance = 2, simply because the test for other comes after the test for medic.

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!

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
  • 3 replies
  • 633 views
  • 0 likes
  • 2 in conversation