BookmarkSubscribeRSS Feed
PotTheCat
Calcite | Level 5

I have a list of 10k + records that contain a 10 digit item number. And an effective date and a term date for each.

Effectively taking an unbroken date span and make a record for each month effective. I have a date span table created 

but have no idea as to how to change the span to per month records. Please see the input output example below. Thank you in advance.

 

Example: 

 

Input

ITEM                EFFDATE         TRMDATE

0123456789     01JAN2018      31JUN2018 

 

Desired Output :

ITEM                  EFFMTH    COUNT 

0123456789      012018       1

0123456789      022018       1

0123456789      032018       1

0123456789      042018       1

0123456789      052018       1

0123456789      062018       1

0123456789      072018       0

0123456789      082018       0

0123456789      092018       0

0123456789      102018       0

0123456789      112018       0

3 REPLIES 3
Reeza
Super User

1. Use INTCK to determine number of intervals

2. Use INTNX to calculate new date variable.

3. Use a LOOP with OUTPUT to explicitly write out new records.

 

data want;
set have;

n_intervals = intck('month', effdate, trmdate);

do i=0 to n_intervals

Date = intnx(month, effDate, i, 'b');
format date yymmn6.;

OUTPUT;
end;

run;

@PotTheCat wrote:

I have a list of 10k + records that contain a 10 digit item number. And an effective date and a term date for each.

Effectively taking an unbroken date span and make a record for each month effective. I have a date span table created 

but have no idea as to how to change the span to per month records. Please see the input output example below. Thank you in advance.

 

Example: 

 

Input

ITEM                EFFDATE         TRMDATE

0123456789     01JAN2018      31JUN2018 

 

Desired Output :

ITEM                  EFFMTH    COUNT 

0123456789      012018       1

0123456789      022018       1

0123456789      032018       1

0123456789      042018       1

0123456789      052018       1

0123456789      062018       1

0123456789      072018       0

0123456789      082018       0

0123456789      092018       0

0123456789      102018       0

0123456789      112018       0


 

PotTheCat
Calcite | Level 5
Worked perfectly. Much appreciated.
novinosrin
Tourmaline | Level 20
data want;
set have;
do while(EFFDATE<TRMDATE);
output;
EFFDATE=intnx('month',EFFDATE,1);
if EFFDATE>TRMDATE then leave;
end;
/*format EFFDATE however you want;*/
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2857 views
  • 2 likes
  • 3 in conversation