Hi!
I have got a variable (v1) like this:
v1
311
1066
4710
4715
and I would like to create another variable (v2)
v2 v1
0 311
312 1066
1067 4710
4711 4715
How can I do it?
Thanks!
In a data step, use the lag() function:
v2 = lag(v1);
if v2 = . /* first observation */
then v2 = 0;
else v2 = v2 + 1;
In a data step, use the lag() function:
v2 = lag(v1);
if v2 = . /* first observation */
then v2 = 0;
else v2 = v2 + 1;
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.