DATA Step, Macro, Functions and more

How to order a column which contains date values ?

Reply
Contributor
Posts: 23

How to order a column which contains date values ?

I have a credit card user data in the below mormat.

 

Card_number    Customer_NumberDate_became_memberMemtype
4.67853E+15589121523/15/1994           P
4.67853E+15589121521/1/2000           A
4.67853E+15589121531/9/2001           P
4.67853E+15589121531/7/2002           A
4.67853E+15589121533/4/1993           A
4.67853E+155891215712/23/1995           P
4.67853E+15589121601/17/2000           P
4.67853E+15589121611/26/2000           P
4.67853E+155891216110/27/1995           A
4.67853E+155891216211/5/2002           P
4.67853E+155891216211/9/1993           A
4.67853E+15589121621/26/2002           A

 

 

But in my data the date_became_member is not icorrect order.I want to create a data set like

below.

 

Card_numberCustomer_NumberDate_became_memberMemtype
4678527546403500589121523/15/1994P
4678527546219220589121521/1/2000A
4678527546976100589121533/4/1993P
4678527546503750589121531/9/2001A
4678527546329640589121531/7/2002A
46785275467686605891215712/23/1995P
4678527546294870589121601/17/2000P
46785275468289605891216110/27/1995P
4678527546666830589121611/26/2000A
46785275466983105891216211/9/1993P
4678527546340550589121621/26/2002A
46785275466127505891216211/5/2002A

 

The main logis is that MEMTYPE =P signifies it is a primary customer and it should have minimum 

date of date became member.MEMTYPE=A signifies the add on card of a customer.

 

Please help me to get my desired output.

 

Super User
Posts: 11,343

Re: How to order a column which contains date values ?

First question is are your dates SAS date values or character? If proc contents shows them with format mmddyy10 or similar then the dates are okay. If not then you likely need to create a SAS date value that will sort correctly.

 

If I understand what you are wanting something like this:

proc sort data= have;
   by Customer_number date_became_member;
run;

data want;
   set have;
   by Customer_number date_became_member;
   if first.customer_number then Memtype='P';
   else Memtype='A';
run;
Ask a Question
Discussion stats
  • 1 reply
  • 139 views
  • 0 likes
  • 2 in conversation