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)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 831 views
  • 0 likes
  • 3 in conversation