Hello Folks,
I want to compare current year with previous year dynamacially in SAS Viya
Actually i have a drop down list of finyear
2018-19 |
And in my list view i will have some columns
ColumnA Current year Previous year
Rice 20000 1000
Wheat 10000 500
Oil 500 200
Now suppose if from drop down list someone will change the filter to 2019-20
then the comparision should be between 2019-20 with 2018-19
Regards,
Harsh Patel
I believe it's doable. Let's go!
Here's two pics of what I created:
And here are the steps I took to achieve this.
Step 1: Create New data items
DateFromMDY(1, 1, Parse(Substring('_par_fiscal_year'p, 1, 4), 'COMMA32.'))
DateFromMDY(1, 1, ( Parse(Substring('_par_fiscal_year'p, 1, 4), 'COMMA32.') - 1 ))
IF ( ( 'Date (Year)'n = 'Year (current)'n ) OR ( 'Date (Year)'n = 'Year (previous)'n ) ) RETURN 'Date (Year)'n ELSE .
Step 2: Drop-down box
Step 3: Crosstab
( 'My Year'n NotMissing )
Please try this and let me know how it went.
Best regards,
Petri
Hello @harshpatel ,
Could you please describe how your "source data" is laid out, especially finyear is interesting? Does it look something like this?
Best regards,
Petri
Hello @harshpatel,
It sounds like you want to compare the data for a given month with the same month from a different year. The basic calculation for this is easy to do by using the ParallelPeriod operator:
Unfortunately, it is not so easy if you want a drop-down list to control which year's data is compared. I am not sure if it is possible to do this while also keeping a dynamic frame of reference.
Maybe someone else can offer a way that this can be done.
Something you can do is have a selector that would pick "Number of years ago": 1 year ago, 2 years ago, and so on. Based on the value of this control, you could have a calculated item that would return different ParallelPeriod calculations for each selection.
Sam
I believe it's doable. Let's go!
Here's two pics of what I created:
And here are the steps I took to achieve this.
Step 1: Create New data items
DateFromMDY(1, 1, Parse(Substring('_par_fiscal_year'p, 1, 4), 'COMMA32.'))
DateFromMDY(1, 1, ( Parse(Substring('_par_fiscal_year'p, 1, 4), 'COMMA32.') - 1 ))
IF ( ( 'Date (Year)'n = 'Year (current)'n ) OR ( 'Date (Year)'n = 'Year (previous)'n ) ) RETURN 'Date (Year)'n ELSE .
Step 2: Drop-down box
Step 3: Crosstab
( 'My Year'n NotMissing )
Please try this and let me know how it went.
Best regards,
Petri
Thank you so much Petri,
It works perfectly for me
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.