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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 504 views
  • 1 like
  • 2 in conversation