BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JKCho
Pyrite | Level 9

I have read similar questions already answered in this community but could not find the exact one I want.

 

I currently have a dataset like

ID error_start error_end

10     2007          2010

30     2005          2008 

50     2009          2011

 

From the above dataset, I want to make a dataset (year from 2003 to 2012) like the below...

if there is an error between the above interval, error=1; else error=0;

I cannot make a code for if there is an error between the start date and the end date, error is 1, otherwise 0. 

Please share your wisdom 🙂 Thank you!

 

ID error  Year

10   0      2003

10   0      2004

10   0      2005

10   0      2006

10   1      2007

10   1      2008

10   1      2009

10   1      2010

10   0      2011

10   0      2012

 

30   0      2003

30   0      2004

30   1      2005

30   1      2006

30   1      2007

30   1      2008

30   0      2009

30   0      2010

30   0      2011

30   0      2012

 

50   0      2003

50   0      2004

50   0      2005

50   0      2006

50   0      2007

50   0      2008

50   1      2009

50   1      2010

50   1      2011

50   0      2012

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Here is a straightforward approach:

data want;
set have;
do year = 2003 to 2012;
error = (error_start <= year <= error_end);
Output;
end;
run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star
Here is a straightforward approach:

data want;
set have;
do year = 2003 to 2012;
error = (error_start <= year <= error_end);
Output;
end;
run;
JKCho
Pyrite | Level 9
Ah... Yeah! I haven't thought about this at all. Thanks!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 816 views
  • 3 likes
  • 2 in conversation