BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kathleen_07
Calcite | Level 5

Hi all,

Below is a screenshot of my data. I am having trouble on how to create a column with Previous Year values. As you can see I need the 2016 year value to be in 2017's previous year column. I have tried multiple versions of retain and lag, but I'm not getting what I need still. Any help would be great!

kathleen_07_1-1608151885553.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Did  prevyear_value = Lag12 (year_value) ; not work? If not show the code you used from the log and describe what is incorrect.

 

If you are hiding some sort of "group", such as company, that needs to reset then you need to include that information in your description and better instead of picture, that we can't code with, provide some example data in the form of a data step. You only need to provide the relevant variables and dummy data is fine as long as it behaves like your actual data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

 

 

View solution in original post

1 REPLY 1
ballardw
Super User

Did  prevyear_value = Lag12 (year_value) ; not work? If not show the code you used from the log and describe what is incorrect.

 

If you are hiding some sort of "group", such as company, that needs to reset then you need to include that information in your description and better instead of picture, that we can't code with, provide some example data in the form of a data step. You only need to provide the relevant variables and dummy data is fine as long as it behaves like your actual data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 865 views
  • 0 likes
  • 2 in conversation