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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 818 views
  • 0 likes
  • 3 in conversation