BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MingZuo
SAS Employee

Hi experts,

image.jpg

i am trying to create a new column (Value 2) that is backdated by 1 month in the excel dataset. Is there an easier way to do this in SAS programming/ SAS Data Preparation on Viya? I believe in excel it can be achieved using a look up. Does SAS provide a similar option?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Try something like this:

proc sort data=have;
by group year month;
run;

data want;
set have;
by group;
prev_year = lag(year);
prev_month = lag(month);
value_2 = lag(value);
if first.group
then do;
  prev_year = .;
  prev_month = .;
  value_2 = .;
end;
run;

proc sort data=want;
by year month group;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS community 🙂

 

If you can provide example data in the form of a data step, we can provide usable code for your problem

Kurt_Bremser
Super User

Try something like this:

proc sort data=have;
by group year month;
run;

data want;
set have;
by group;
prev_year = lag(year);
prev_month = lag(month);
value_2 = lag(value);
if first.group
then do;
  prev_year = .;
  prev_month = .;
  value_2 = .;
end;
run;

proc sort data=want;
by year month group;
run;
MingZuo
SAS Employee

Hi,

 

thanks for the solution, it works!

 

Last but most importantly, i wish to create the same column of "value" in the same manner in SAS Visual Analytics. Are there any means to use the Aggregated (Periodic) in the calculated item to create?

 

i want to visualize the comparison in VA, to be something like this below.

 

Thanks again!

 

2018-12-06_15-59-53.jpg

Kurt_Bremser
Super User

You better ask this question in the Visual Analytics community. I have no experience with VA myself.

Include a link to this thread in your new question. (use this button:link.jpg)

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1507 views
  • 0 likes
  • 3 in conversation