I have variable named date with value
date=2020
and i want to get the previous year based on the value in the date column i.e 2019.
how do i get that.??
This does noot seem to be a date varaible? Rather a year variable?
If so, then simply subtract 1:
data _null_;
date1 = 2020;
date2 = date1 - 1;
put date1 = / date2 =;
run;
@Son_Of_Krypton wrote:
I have variable named date with value
date=2020
and i want to get the previous year based on the value in the date column i.e 2019.
how do i get that.??
date - 1
Hi @Son_Of_Krypton Are you seriously asking a subtraction question? Or are you trying to mean previous as LAG, as in previous value read in queue from the previous record in a dataset?
If you used the YEAR() function, then the numeric value can be used in a simple subtraction.
Right, I am afraid I am still not clear with your objective.
You mentioned you have a date variable with a value 09NOV2020
Extracting the YEAR value from the date value would indeed give you 2020. And then just like other's suggestion it should be year(date)-1 however this will give 2019. So when your "year" is already 2020, I would think you do not need to subtract unless you want 2019.
Am i mistaken, or is it the damn starbucks coffee not strong enough?hmm
if year(dateVariable) = 2020 then Test=intnx('Year', dateVariable, -1);
Replace the dateVariable with the name of your variable and you're fine.
@Son_Of_Krypton wrote:
no i am having date like 09NOV2020 and then i extracted year from it i.e 2020 based on this year i want previous year in another variable
I know that it can be done via intnx on date 09NOV2020 like
Test=intnx('Year','09NOV2020'd,-1);
Test2=Year(Test);
but is it possible to do on year 2020 only.??
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.