Hi experts,
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!
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;
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
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;
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!
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:)
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.