BookmarkSubscribeRSS Feed
spg
Obsidian | Level 7 spg
Obsidian | Level 7

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!

3 REPLIES 3
Reeza
Super User

Try the vvaluex function.

Reeza
Super User

data test;

     set have;

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

run;

Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1470 views
  • 0 likes
  • 3 in conversation