BookmarkSubscribeRSS Feed
rameshmodi04
Calcite | Level 5

I would like to know the logic for extracting transactions occurred with in 10 min , i have date, time with seconds, credit card and amount variables.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Show us a portion of the data. Follow these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

Also, describe the logic you want to use in more detail. Within 10 minutes of what?

--
Paige Miller
rameshmodi04
Calcite | Level 5

I am sorry unfortunately i cannot share the data. 

I have different credit card transactions at particular merchant. I would like to check from first transaction with in 10 minutes of time how many transaction happen irrespective of first transaction time.

PaigeMiller
Diamond | Level 26

Make up some data, in the exact same format as the real data.

 

I have different credit card transactions at particular merchant. I would like to check from first transaction with in 10 minutes of time how many transaction happen irrespective of first transaction time.

This still is vague in my mind, and can be interpreted differently by different people. Provide a few representative examples (plural) in your fake data set and explain the desired output.

--
Paige Miller
ballardw
Super User

The following data steps first create some datetime values for a few IDs at random intervals in minutes.

The second then shows how to determine the interval of a given datetime value from the first one.

You would use your account information in place of ID and likely requires sorting by the account information and the datetime of the transaction.

If you do not have a datetime value, which you will need, then the code will show how to add time values in hour minute seconds, if separate values, to a date.

data example;
  do id = 1, 2, 3;
   do date='11Jul2020'd, '12Jul2020'd;
      hour = rand('integer',1,15);
      min  = rand('integer',1,18);
      sec  = rand('integer',1,53);
      datetime= dhms(date, hour,min,sec);
      output;
      do i= 1 to 10;
         rmin= rand('integer',1,15);
         datetime = intnx('minute',datetime,rmin);
         output;
      end;
   end;
  end;
  format datetime datetime18.;
  keep id datetime;
run;

data want;
   set example;
   by id;
   retain firsttime;
   if first.id then firsttime=datetime;
   interval = intck('minute',firsttime,datetime,'C');
   format firststime datetime18.;
   label interval="# minutes from first record for id";
run;

Set a flag for the interval value of interest to count as needed.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 750 views
  • 1 like
  • 3 in conversation