BookmarkSubscribeRSS Feed
Adnan_Razaq
Calcite | Level 5

Hi All,

 

I have the following dataset

 

data have;
	input reporting_date account_id $ repayment_type $; 
	informat reporting_date  date9.;
	format reporting_date date9.;
	
	cards ;
	31JAN2018 123 REP
	31JAN2018 456 INT
	31JAN2018 789 PAP
	28FEB2018 123 REP
	28FEB2018 456 .   
	28FEB2018 789 PAP 
	31MAR2018 123 .   
	31MAR2018 456 .   
	31MAR2018 789 .   
	;
run;

What I need to get to is

 

 

Reporting_DateAccount_IDRepayment_Type
31-Jan-18123REP
31-Jan-18456INT
31-Jan-18789PAP
28-Feb-18123REP
28-Feb-18456INT
28-Feb-18789PAP
31-Mar-18123REP
31-Mar-18456INT
31-Mar-18789PAP

 

I need to retain the repayment type only if the repayment type is missing the following month.

 

Regards

 

Adnan

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats very simple, did you read the examples in the SAS docs?

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=p0t2ac0tfzcgbjn112mu96hkgg9o.htm&docs...

 

Maybe something like:

data want;
  set have;
  retain lst;
  if lst ne "" then lst=repayment_type;
  else repayment_type=lst;
run;
Ksharp
Super User
data have;
	input reporting_date account_id $ repayment_type $; 
	informat reporting_date  date9.;
	format reporting_date date9.;
	
	cards ;
	31JAN2018 123 REP
	31JAN2018 456 INT
	31JAN2018 789 PAP
	28FEB2018 123 REP
	28FEB2018 456 .   
	28FEB2018 789 PAP 
	31MAR2018 123 .   
	31MAR2018 456 .   
	31MAR2018 789 .   
	;
run;

data want;
 set  have ;
 by reporting_date;
 if first.reporting_date then n=0;
 n+1;
 if n=1 then repayment_type='REP';
 if n=2 then repayment_type='INT';
 if n=3 then repayment_type='PAP';
drop n;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 629 views
  • 0 likes
  • 3 in conversation