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;
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!
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.
Ready to level-up your skills? Choose your own adventure.