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;

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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