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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.