BookmarkSubscribeRSS Feed
Question
Fluorite | Level 6

Hi All,

I would like to create a transaction_id based on Sale Date ...Please see an exampe below...Each customer will have a different trans_id for each date he has transacted,,,I hoe it does make sense.

Many Thanks for your help..

Customer_IDTransaction_IDItem_IDDay_of_the_weekSale_dateQuantityStore_DepartmentItem_NameItem_Category
2492372342210145027 Sun08/04/20011GROCERY DEPTPC SQZ KETCHUP 28OZOTHER
2492372342210173107 Sun08/04/20011DELI DEPTROAST BEEFCOLD CUTS
2492372342210173307 Sun08/04/20011DELI DEPTHOFMANN HOT DOGCOLD CUTS
2492372342210175467 Sun08/04/20011DELI DEPTCOLE SLAWSALADS
2492372342210176377 Sun08/04/20011PRODUCE DEPTFANCY BANANAPRODUCE
2492373142410190332 Tue10/04/20012MEAT DEPTSWFT MAPLE B&S LINKSMEAT
2492373142410205402 Tue10/04/20011FROZEN DEPTRICHS BREAD DOUGH 5LVSFROZEN FOODS
2492373142410280562 Tue10/04/20011DAIRY DEPTBYRNE SKIM MILK QTDAIRY
2492373142410280572 Tue10/04/20011DAIRY DEPTBYRNE CHOC MILK QTDAIRY
2492373542510280564 Thu12/04/20011DAIRY DEPTBYRNE SKIM MILK QTDAIRY
7 REPLIES 7
LinusH
Tourmaline | Level 20

What do want to do with this id?

Does it have to numerical?

Otherwise, just concatenate the two columns:

catx('_',customer_id, put(sale_date,best.)

Otherwise, have your data sorted by customer and sale date.

Then just lop tru your table with a data step and increase the trans id by 1 for each new first.sale_date.

Data never sleeps
Sudhakar_A
Calcite | Level 5

hi,

We can create the transaction id based on each uniques customer and sale date? how do you want the transaction id should be is it a continous one? or you need any pattern  like starting with 3733141... like that ?

Question
Fluorite | Level 6

Hi Sudhakar,

Any pattern will do..

Thank You

Alice

Ksharp
Super User
data have;
input id date : mmddyy10.;
format      date  mmddyy10.;
cards;
2492 08/04/2001
2492 08/04/2001
2492 08/04/2001
2492 08/04/2001
2492 10/04/2001
2492 10/04/2001
2492 10/04/2001
;
run;
data have ;
 set have;
 by id date;
 retain Transaction_ID;
 if first.date then Transaction_ID=int(10000000*ranuni(0));
run;

Ksharp

Question
Fluorite | Level 6

Many Thanks Ksharp...

Alice

Sudhakar_A
Calcite | Level 5

data have ;

     set have;

     by id date;

     retain Transaction_ID;

     if first.date then Transaction_ID=37245500+1;

run;

Sudhakar_A
Calcite | Level 5

Hi Alice,

Ksharp is correct actually that is the answer i was about to give.

Sudhakar

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 1288 views
  • 0 likes
  • 4 in conversation