Flag and repeat

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Flag and repeat

Hi,

 

I have a data set like this:

1.png

What I want is like this:

 

2.png

 

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
Trusted Advisor
Posts: 1,204

Re: Flag and repeat

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

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

View solution in original post


All Replies
Super User
Posts: 10,476

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

Thank you for your answer!

 

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
Trusted Advisor
Posts: 1,204

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.

Need further help from the community? Please ask a new question.

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