Help using Base SAS procedures

Matching year with marital status

Reply
Contributor spg
Contributor
Posts: 61

Matching year with marital status

Hi,

This follows from a question I'd posted earlier. My data looks like this, each person's purchase of a particular product at a given year...and his/her marital status over the years (Married or Divorced). I need a single column that will give me the marital status according to year of purchase. So for person 1, the STATUS should be Married, person 2 Married, person 3 Divorced etc.

How can I get at this?

PersonYear of purchaseM_2009M_2010M_2011M_2012D_2009D_2010D_2011D_2012STATUS
1200911000011Married
2201211110000Married
32012 0 1Divorced
42011 10 01
5200900001111
62010 000 111
72011 11 00

Thanks!

Super User
Posts: 19,822

Re: Matching year with marital status

Try the vvaluex function.

Super User
Posts: 19,822

Re: Matching year with marital status

data test;

     set have;

    Status=ifc(vvaluex("M_"||put(year_purchase, 4.))=1, "Married", "Divorced");

run;

Super User
Posts: 5,513

Re: Matching year with marital status

Untested, but it should be working:

data want;

set have;

array marr {2009:2012} M_2009 - M_2012;

length status $ 8;

if marr{year}=1 then status='Married';

else status='Divorced';

run;

I guess if I were looking for job security, I might code this after the LENGTH statement:

status=substr('DivorcedMarried ', 1 + marr{year}*8, 8);

All the code does assume that Year is always within range, always takes on the right value, and that the Divorced/Married pairs are always the opposite of one another for any given year.

Good luck.

Ask a Question
Discussion stats
  • 3 replies
  • 158 views
  • 0 likes
  • 3 in conversation