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