Hello lads,
I have the following data (just a small example):
Location -- Section -- Date -- Counts
Germany -- SA -- 29/04/2020 -- 20
Germany -- SA -- 28/04/2020 -- 67
Germany -- SA -- 27/04/2020 -- 34
Germany -- SA -- 26/04/2020 -- 56
Germany -- SB -- 29/04/2020 -- 76
Germany -- SB -- 28/04/2020 -- 43
Germany -- SB -- 27/04/2020 -- 44
Germany -- SB -- 26/04/2020 -- 90
The dataset contains data of more that 1 year back, it gets updated every day. I want to select just the counts of the last 30 days (per location and section!). Hope someone can help me out with this..
Thanks in advance 🙂
data want;
set have;
where date ge today() - 30;
run;
data want;
set have;
where date ge today() - 30;
run;
@AK100 wrote:
I assume ge stands for Greater then or Equal?
Correct. The mnemonic for "greater" is gt. I like to use the mnemonics to avoid confusion when a certain character is not readily available on a keyboard, or might be changed somewhere along the way by some software converting it to a Unicode character.
I also tried to do the same for the past 3 months(not 90 days). I figured out the following code (with the help of one of your codes in some other topic):
data want;
set want;
where intnx('month',today(),-3,'same') <= datum <=today();
run;
I wondered if there was an easier code to do this?
@AK100 wrote:
I also tried to do the same for the past 3 months(not 90 days). I figured out the following code (with the help of one of your codes in some other topic):
data want;
set want;
where intnx('month',today(),-3,'same') <= datum <=today();
run;
I wondered if there was an easier code to do this?
Using the INTNX function for this is the proper way, as it takes care of different month lengths. I see nothing wrong here.
Please post your data in usable form (data step with datalines), and the code you ran against it. I will test it and see what went wrong.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.