Generate date using DFSORT



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Generate date using DFSORT

Postby puffes » Mon Dec 21, 2015 10:37 pm

Hi,
I wonder if it's possible to generate all dates for one year using DFSORT?
So for year 2016 I want to generate 366 records on a sequential file starting with value 2016-01-01, 2016-01-02 and so on

Regards,

Mikael
puffes
 
Posts: 5
Joined: Wed Mar 12, 2014 12:46 am
Has thanked: 0 time
Been thanked: 0 time

Re: Generate date

Postby BillyBoyo » Tue Dec 22, 2015 1:23 am

Yes. Look at REPEAT in OUTFIL and the date functions, where there are a number of ways to do it. You can add a sequence number to a base date, or PUSH the date and get the next day...
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Generate date

Postby puffes » Tue Dec 22, 2015 4:32 pm

Hi again,
I've tried but I don't managed to get it right.

The file should contain:
Pos 1-6 Date in format YYMMDD
Pos 7-9 Day of year (001-366)
Pos 10-11 Week (01-52)
Pos 12 Day of week (1-7)

So the can look like this:
160101001536
160102002537
160103003531
160104004012
160105005013
and so on

How do I write it using Repeat other functions?

Regards

Mikael
puffes
 
Posts: 5
Joined: Wed Mar 12, 2014 12:46 am
Has thanked: 0 time
Been thanked: 0 time

Re: Generate date

Postby enrico-sorichetti » Tue Dec 22, 2015 5:39 pm

Pos 10-11 Week (01-52)


do the application designers know about the quirks of the week number ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Generate date

Postby prino » Tue Dec 22, 2015 10:21 pm

enrico-sorichetti wrote:
Pos 10-11 Week (01-52)


do the application designers know about the quirks of the week number ?

I guess that question is meant to be rhetorical. :mrgreen: :mrgreen: :mrgreen:
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Generate date

Postby enrico-sorichetti » Tue Dec 22, 2015 10:38 pm

Naturally ;)

I have been repeating the concept ad nauseam ...
people asking on forums just care about the lowly technicalities
and completely forget about proper business concerns.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Generate date

Postby enrico-sorichetti » Tue Dec 22, 2015 11:12 pm

I just reread the whole topic and ...

as usual the code and the data do not match the comments
the comment talk about week number from 1 to 52,
but the data has the right week
16/01/01 is week number 53
and the wrong week day

and anyway another column is needed for the year

the comment for poor analysis still stands ( thanks &deity )

the algorithm is still wrong ...

for 16/01/01 it reports week 53 day 6
but
for 16/01/03 it reports week 53 day 1

a good analysis implies ( for congruency ) monotonicity of data

I suggest to number with 1 staring from monday

so that week 53 of 2015 will span into 2016 with the proper monotone days of the week

for 16/01/01 year 2015 week 53 day 5
for 16/01/03 year 2015 week 53 day 7
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Generate date

Postby enrico-sorichetti » Tue Dec 22, 2015 11:29 pm

very good mode on
here a rexx snippet to do the calculations
tested and working on my pc using open object rexx

#! /usr/bin/rexx

/* REXX
      y         year
      d         day
      w       week

      s         date sorted   yyyymmdd
      b         date base   ( as per rexx definition 0 = monday/00010101 )

      fwky      procedure,
            returns the base date of the monday of the first week of a year
            the week containin the thursday

      iso1      procedure,
            format the iso date appropriately

*/

parse arg s k
if k = "" then k = 1

f = date("b",right(s,4,"0") || "0101", "S")
t = date("b",right(s+k,4,"0") || "0101", "S" ) - 1

do   b  = f to t
   s = date("S",b,"B")
   i = date2iso(s)
   if   s \=  iso2date(i) then do
         say "error for" b s i
         exit
   end
   if   k = 1 then ,
         say s b i
end

exit

date2iso : procedure
   parse arg s
   b = date("B", s, "S")
   y = left(s, 4 )

   /* the easy one first */
   if   b >= fwky(y+1 ) then ,
       return iso1(y+1, 1, b // 7 + 1 )

      if   b >= fwky(y ) then do
         w = b % 7 - fwky(y ) % 7 + 1
         return iso1(y, w, b // 7 + 1 )
      end

      w = b % 7 - fwky(y-1 ) % 7 + 1
      return iso1(y-1, w, b // 7 + 1 )

iso1: procedure
      parse arg y, w, d
      return right(y, 4, "0" ) || "W" || right(w, 2, "0" ) || d

iso2date:procedure
      parse arg i
      parse var i with 1 y 5 . 6 w 8 d
      b = fwky(y ) + (w - 1 )*7 + d - 1
      return date("S", b, "B")

fwky: procedure
      /* base date of the first week of the year */
      parse arg y
      w = date("b", right(y, 4, "0" ) || "01" || "01", "s" )
      d = w // 7 + 1
      if   d <= 4 then ,
       return w + 1 - d
      else ,
       return w + 1 - d + 7
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post