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

I have a table as below

 

|    Year    |    Month    |     Income    |

----------------------------------------

|   2020   |     1              |      50            |

|   2020   |     4             |      70            |

|   2021    |     2             |      80            |

|   2021    |     11            |      70            |

|   2022   |     9             |      50            |

|   2022   |     11            |      54            |

|   2022   |     12           |      90            |

|   2023   |     2             |      70            |

|   2023   |     4             |      50            |

|   2023   |     6             |      40            |

|   2023   |     10           |      30            |

--------------------------------------

 

I would like to create a table from the have where year is the most recent year and the previous year. I do not want to use "where year in (2022, 2023)" because the year may change.

 

I tried in two different ways,

 

Data want; set have;
where year ge last.year-1;
run;

Data want; set have;
where year ge max.year-1;
run;

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%let yr = %sysfunc(year(%sysfunc(today())));

data want;
    set have;
    if year>=%eval(&yr-1);
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
%let yr = %sysfunc(year(%sysfunc(today())));

data want;
    set have;
    if year>=%eval(&yr-1);
run;
--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 620 views
  • 1 like
  • 2 in conversation