Hi, everyone.
My question is that how to numbering each observation. (please look at the below dataset and focus on # of forecasts before the forecast column)
Company Year Quarter forecast # of forecasts before the forecast
A 1993 1 xxx 0
A 1 xxx 1
A 2 xxx 2
A 3 xxx 3
A 4 xxx 4
B 1993 1 yyy 0
B 2 yyy 1
B 3 yyy 2
C 1995 1 zzz 0
C 2 zzz 1
C 3 zzz 2
Any comments or help will be appreciated. Thank you.
Best,
Steve
data want;
set have;
by Company ;
if first.Company then n=-1;
n+1;
run;
data want;
set have;
by company;
if first.company then num=0;
else num+1;
run;
proc print;
run;
Note: code is not tested but i hope it fulfilled your requirement :
proc sort data=have;
by company;
run;
data req;
set have;
by company;
if first.company then num=1;
output;
num+1;
run;
You can try this one.
proc sort data=have;
by company;
run;
data want (drop=n);
set have;
by company;
if first.company then n=0;
n+1;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.