BookmarkSubscribeRSS Feed
SteveLee
Calcite | Level 5

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

4 REPLIES 4
Ksharp
Super User

data want;

set have;

by Company  ;

if first.Company   then n=-1;

n+1;

run;

bharathtuppad
Obsidian | Level 7

data want;

set have;

by company;

if first.company then num=0;

else num+1;

run;

proc print;

run;

Dalveer
Calcite | Level 5

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;

HarryLiu
Obsidian | Level 7

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;

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2047 views
  • 2 likes
  • 5 in conversation