Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to number table observationss for each customer? 1

Status
Not open for further replies.

iren

Technical User
Mar 8, 2005
106
US
I have cust_num and order_date fields. Some customers have only one order while others have more. Therefore some of them have only one records while other have more records.

I need an additional column ORDER_SEQUENCE with a asc sequence of the of the orders (1,2,3...).
Also if the same customer has more than one order at the same day I need another additional column NOTE with a value
"multiple orders".

cust_num order_date Order_sequence note
11 2/12/2007 1
11 3/10/2008 2
12 1/5/2005 1 multiple
12 1/5/2005 2 multiple
13 3/13/2004 1
14 4/3/2009 1
14 5/3/2009 2
14 7/4/2009 3

Could you please help me with it?

Thank you in advance,

Iren
 
Try this.
Code:
data dat2;
  set dat1;

  by cust_num order_date;

  retain order_sequence 0;

  if first.cust_num then order_sequence = 1;
  else order_sequence + 1;
run;
The data obviously needs to be sorted in the order that you want it numbered in. The by statement doesn't need the "order_date" in there, however, putting it there makes sure that the code will fail if the data is not sorted in the correct order, so is a good safety feature.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top