Focal Point
[CLOSED] Best method to generate a list of months in a date range

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8027005806

August 17, 2011, 03:19 PM
Keith MacDonald
[CLOSED] Best method to generate a list of months in a date range
I'm going to need to graph a number (ie, count of something) for every month. But it's possible the data has no records during a month that will be during the specified period.

So for example....

2011/01 5
2011/02 0
2011/03 0
2011/04 10

etc.

I can do the counts easily enough, but need the months list to start from. I'd prefer to generate the list of months on the fly, since I'll know the start and end month anyhow. Then I can join the data to that and calculate on from there.

So - has anyone done something like this before? I'd need to generate the list of months as well as the master file, but I'd love to clear both afterwards as if they were a hold file.

I could do a loop with -write in dialogue manager and use a dos command to delete the files afterwards...but surely there must be a better way??

This message has been edited. Last edited by: Keith MacDonald,


WebFOCUS & DataMigrator 7.7.03M
Windows 2003, Windows 2008 x64
August 17, 2011, 03:30 PM
ABT
Would DATEDIF for your start/end date and an M flag work?


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
August 17, 2011, 03:37 PM
Keith MacDonald
Sure, Datedif could work to create the list of dates. I could do that with dialogue manager and -WRITE. But that doesn't generate a master file (automatically) and also leaves a file behind after execution. I was trying to think of a way to...create a hold file? Rather than a SAVE file.


WebFOCUS & DataMigrator 7.7.03M
Windows 2003, Windows 2008 x64
August 17, 2011, 04:47 PM
Doug
Consider using ROWS or COLUMNS to complete the list of desired months...
August 17, 2011, 04:47 PM
j.gross
quote:
I was trying to think of a way to...create a hold file?

Start here.

To create a month-dimension file:
EX MAKESEQ, with
FIRST=0,
LAST=(the number of months in the period of interest, minus 1).

DEFINE Month (in FSEQ) as the initial date plus COUNTER months.

Then merge with the original HOLD file (using MATCH FILE) to supply rows with zero-valued statistics for the idle months.

This message has been edited. Last edited by: j.gross,
August 17, 2011, 04:53 PM
jfr99
Hi Keith,

Take a look at this and see if this might work. This creates a temp file along with a master file.

-*****************************************************************
-*
-SET &BEG_MO = 201006;
-SET &END_MO = 201112;
-*
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-TYPE +++ LOOPER - CREATE DATEFILE +++
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FILEDEF DATEFILE DISK your_datefile_data.txt
-RUN
-TYPE ******* BEGIN LOOP *******
-SET &THE_MO = &BEG_MO;
-:LOOPER
-TYPE THE_MO ----- &THE_MO
-WRITE DATEFILE &THE_MO
-SET &THE_MO = AYM(&THE_MO, 1, 'I6YYM');
-IF &THE_MO GT &END_MO GOTO :EOF;
-GOTO :LOOPER
-:EOF
-CLOSE
-TYPE ******* END LOOP *******
-RUN
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-TYPE +++ MASTER - YOURDATE +++
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FILEDEF MASTER DISK yourdate.mas
-RUN
-WRITE MASTER FILE=YOURDATE, SUFFIX=FIX, $
-WRITE MASTER SEGNAME=YOURDATE, SEGTYPE=S0, $
-WRITE MASTER FIELDNAME=YOUR_MO, ALIAS=YOUR_MO, USAGE=YYM, ACTUAL=A06, $
-CLOSE
-RUN
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-TYPE +++ FILEDEF - YOURDATE +++
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FILEDEF YOURDATE DISK your_datefile_data.txt
-RUN
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-TYPE +++ REPORT - YOURDATE +++
-TYPE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TABLE FILE YOURDATE
PRINT
YOUR_MO
-*ON TABLE HOLD
END
-RUN
-*****************************************************************

Let me know if you have questions.
Jim


WebFocus 8.201M, Windows, App Studio
August 18, 2011, 12:51 PM
GaryB
This one is like Jim's, but it uses the -REPEAT.

-* File dates_months.fex
-DEFAULT &STARTDATE     = '2011/01/01';
-DEFAULT &ENDDATE       = '2011/12/31';
-SET &BLANK = ' ';
-SET &NUMBER = DATEDIF(&STARTDATE.QUOTEDSTRING,&ENDDATE.QUOTEDSTRING,'M');
-SET &STARTDATE_A8 = STRIP(10,&STARTDATE.QUOTEDSTRING,'/', 'A8');
FILEDEF TEMPDATES DISK (APPEND
-RUN
-REPEAT RPT_LOOP FOR &COUNTER FROM 0 TO &NUMBER;
-SET &DAYPLUS= DATEADD(DATECVT(&STARTDATE_A8.QUOTEDSTRING,'I8YYMD','YYMD'),'M',&COUNTER);
-SET &TODAY = DATECVT(&DAYPLUS.EVAL,'YYMD','A8YYMD');
-WRITE TEMPDATES NOCLOSE &TODAY.EVAL &COUNTER.EVAL &BLANK.EVAL
-RPT_LOOP
-CLOSE TEMPDATES
FILEDEF MAS DISK TEMPDATES.MAS
-RUN
-WRITE MAS FILENAME=TEMPDATES, SUFFIX=FIX    , $;
-WRITE MAS FIELDNAME=TODAY,ALIAS=, USAGE=A8YYMD, ACTUAL=A8 ,$
-WRITE MAS FIELDNAME=COUNTER,ALIAS=, USAGE=I4, ACTUAL=A4 ,$
-WRITE MAS FIELDNAME=BLANK,ALIAS=, USAGE=A1, ACTUAL=A1 ,$
-CLOSE MAS
TABLE FILE TEMPDATES
PRINT
TODAY
COUNTER
BY BLANK
ON TABLE HOLD AS TEMPDTS FORMAT XFOCUS INDEX BLANK
END
-RUN
TABLE FILE TEMPDTS
PRINT *
END
-EXIT


Gary
August 18, 2011, 02:57 PM
Keith MacDonald
Thanks folks, these are some good ideas!


WebFOCUS & DataMigrator 7.7.03M
Windows 2003, Windows 2008 x64