## Flag and repeat

Solved
Occasional Contributor
Posts: 14

# Flag and repeat

Hi,

I have a data set like this:

What I want is like this:

The years of 2004 and 2008 are benchmarks I identified. I want to use these two benchmarks as initial years to calculate ages for relative years.

The data set I am working with is very large, what I showed in the figure is just one group identified by several other attributes.

Is there any way that can accomplish this?

Thanks!

Accepted Solutions
Solution
‎04-12-2016 03:53 PM
Posts: 1,270

## Re: Flag and repeat

data want(drop=flag rename=flag1=flag);

set have;
retain flag1;
if flag ne . then flag1=flag;
run;

All Replies
Super User
Posts: 13,563

## Re: Flag and repeat

Is there a rule involved? It looks like if EFF_Year is 2004 to 2007 then assign 2004 and possibly a range but not specified if EFF_Year is 2008 to some value then assign 2008. Is this the case? If so, what is the largest value of EFF_Year that should receive an assignment to flag of 2008?

These could look like:

data want;

set have;

If  2004 le EFF_Year le 2007 then flag=2004;

else if 2008 le Eff_year le 2009 then flag = 2008; /*<= replace 2009 if you have a different upper bound*/

/* add similar statements if you have other groups*/

run;

If you have a large number of groups there may be other approaches but the Rule needs to be provided. Example results do not always provide sufficient details of rules.

Occasional Contributor
Posts: 14

## Re: Flag and repeat

Actually, I thought I was looking for some statements like "retain", because I have thousands groups and different benchmarkes.

Solution
‎04-12-2016 03:53 PM
Posts: 1,270

## Re: Flag and repeat

data want(drop=flag rename=flag1=flag);

set have;
retain flag1;
if flag ne . then flag1=flag;
run;

🔒 This topic is solved and locked.