BookmarkSubscribeRSS Feed
MalikShahbazz
Calcite | Level 5

Hello, 

 

I have some data stored in SAS in the following form - 

 

Txn IDMonthValue
1201811120
1201812240
1201902350
1201903400
1201905100
2201812200
2201902300

 

I essentially want to fill up the missing month values until say May of this year, this is the data that I want - 

 

Txn IDMonthValue
1201811120
1201812240
120190124
1201902350
1201903400
1201904400
1201905100
2201812200
2201901200
2201902300

 

Could someone help me with this , please!

3 REPLIES 3
Reeza
Super User
PROC TIMESERIES or PROC EXPAND are good options.
novinosrin
Tourmaline | Level 20

Hi @Reeza  Hope you are well. Thank you so much for the mention in the other thread and for the response in the thread I initiated. As always your kindness speaks volumes. I will PM  in regards to the change in situation in my life(slowdown here 😞  ) having to move to Bridgeport, CT to pursue a new career opportunity. Loving CT though.   @ChrisHemedinger 's  help hopefully should get me back in full swing. Take care & See ya soon!

 

@MalikShahbazz  If you do not have ETS

 

data have;
input TxnID	Month : yymmn6.	Value;
format Month  yymmn6.;
cards;
1	201811	120
1	201812	240
1	201902	350
1	201903	400
1	201905	100
2	201812	200
2	201902	300
;

proc means data=have nway noprint;
class txnid;
var month;
output out=temp(drop=_type_ _freq_) min=_min max=_max;
run;

data want ;
if _n_=1 then do;
  if 0 then set have;
   dcl hash H (dataset:'have') ;
   h.definekey  ("txnid","month") ;
   h.definedata ("value") ;
   h.definedone () ;
   end;
set temp;
month=_min;
do while(month<=_max);
_rc=h.find();
output;
month=intnx('month',month,1);
end;
drop _:;
run;

Of course I could do it one step, however the purpose for lazy folks like me to avoid gymnastics along with retain and parking. Cheers!

 

 

 

 

 

 

Ksharp
Super User

Thanks @novinosrin 's dataset .

 

data have;
input TxnID	Month : yymmn6.	Value;
format Month  yymmn6.;
cards;
1	201811	120
1	201812	240
1	201902	350
1	201903	400
1	201905	100
2	201812	200
2	201902	300
;

data want;
 merge have have(keep=txnid month rename=(txnid=_id month=_month) firstobs=2);
 output;
 if txnid=_id then do;
   do i=1 to intck('month',month,_month)-1;
    month=intnx('month',month,1);output;
   end;
 end;
drop _: i;
run;
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1173 views
  • 4 likes
  • 4 in conversation