BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
miguelito
Fluorite | Level 6

Hello Dear SAS users,

 

I have the following tricky problem and I would appreciate your great help:

 

I have data, where I know the start and the end (finish) year per id as you see below. I want to assign 0 to a record that is outside of the range and 1 otherwise:

 

id    start     finish         start_year         end_year        want

1     2010    2015         2008                 .                       0

1     2010    2015         2009                 .                       0

1     2010    2015         2010                2011                 1

1     2010    2015         2011                2012                 1

1     2010    2015         2012                2013                 1

1     2010    2015         2013                2014                 1

1     2010    2015         2014                2015                 1

1     2010    2015         2015                .                        1

1     2010    2015         2016                .                        0

2     2008    2016         2008                2009                 1

2     2008    2016         2009                 .                       1

2     2008    2016         2010                2010                 1

2     2008    2016         2011                2012                  1

2     2008    2016         2012                .                        1

2     2008    2016         2013                2013                 1

2     2008    2016         2014                2015                 1    

2     2008    2016         2015                2016                 1

2     2008    2016         2016                .                        1

3     2013    2014         2008                .                        0

3     2013    2014         2009                 .                       0

3     2013    2014         2010                .                        0

3     2013    2014         2011                .                        0

3     2013    2014         2012                .                        0

3     2013    2014         2013                2014                 1

3     2013    2014         2014                .                        1    

3     2013    2014         2015                .                        0

3     2013    2014         2016                .                        0

 

 

         

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I think this is all you need.

 

if start <= start_year <= finish then flag=1; else flag=0;

View solution in original post

4 REPLIES 4
ballardw
Super User

How do we know what is " outside of the range "?

Use the actual column headings you display because "end" or "finish" could be either the variable Finish or End_year. Plus you have have START and START_YEAR.

So the range could be Start-Finish or Start_year-Finish or Start-End_year or Start_year-End_year. And which explicit variable are we considering within which pair?

miguelito
Fluorite | Level 6

outside of range would be below the start and above the finish per id as the 0's and 1's illustrate above. So, 0 means outside and 1 means inside the range

miguelito
Fluorite | Level 6
The range I am interested is Start-Finish. Equivalently, we could use Start_year and End_year, but as you see above there are missing values that fall into the range and others that do not. Again, the range is defined by Start and Finish. Thank you and I hope you can provide some guidance with the code.
Reeza
Super User

I think this is all you need.

 

if start <= start_year <= finish then flag=1; else flag=0;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 779 views
  • 0 likes
  • 3 in conversation