BookmarkSubscribeRSS Feed
shuvaya
Calcite | Level 5

Hi,

 

I have a dataset which looks like the below:

idFirst_Qual_MonthTxn_Month
1000361Jul-19Jul-19
1000361Jul-19Aug-19
1000361Jul-19Sep-19
100897Jan-20Oct-19
100897Jan-20Nov-19
100897Jan-20Dec-19
100897Jan-20Jan-20
100897Jan-20Feb-20
100897Jan-20Mar-20

 

I need to select only those rows for each id where the months are after the first_qual_month. I can select upto next 6 months of data per user.

Can someone please help me on this? I am new to sas and first. doesn't look to be the solution!

2 REPLIES 2
PeterClemmensen
Super User

See if you can use this as a template.

 

Feel free to ask 🙂

 

options yearcutoff = 2000;

data have;
input id $ First_Qual_Month $ Txn_Month $;
datalines;
1000361 Jul-19 Jul-19
1000361 Jul-19 Aug-19
1000361 Jul-19 Sep-19
100897  Jan-20 Oct-19
100897  Jan-20 Nov-19
100897  Jan-20 Dec-19
100897  Jan-20 Jan-20
100897  Jan-20 Feb-20
100897  Jan-20 Mar-20
;

data want;
   do c = 1 by 1 until (last.id);
      set have;
      by id;
      if input(First_Qual_Month, monyy6.) < input(Txn_Month, monyy6.) then output;
      if c = 6 then leave;
   end;
run;
andreas_lds
PROC Star

As always: store dates as dates and you can use simple where-statements.

data have;
   length id $ 10 First_Qual_Month Txn_Month $ 6;
   input id First_Qual_Month Txn_Month;
   datalines;
1000361  Jul-19   Jul-19
1000361  Jul-19   Aug-19
1000361  Jul-19   Sep-19
100897   Jan-20   Oct-19
100897   Jan-20   Nov-19
100897   Jan-20   Dec-19
100897   Jan-20   Jan-20
100897   Jan-20   Feb-20
100897   Jan-20   Mar-20
;

data fixed_dates;
   set have;
   length FirstQualMonth TxnMonth 8;
   format FirstQualMonth TxnMonth mmyyd8.;
   
   FirstQualMonth = input(First_Qual_Month, monyy6.);
   TxnMonth = input(Txn_Month, monyy6.);
   
   drop First_Qual_Month Txn_Month;
   rename 
      FirstQualMonth = First_Qual_Month 
      TxnMonth = Txn_Month
   ;
run;

data want;
   set fixed_dates;
   where First_Qual_Month < Txn_Month;
run;

What should happen, if more than six obs have First_Qual_Month < Txn_Month?

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 242 views
  • 0 likes
  • 3 in conversation