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.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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