Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to scramble day part of a date

    Hi all - I have a variable (named: DDate) which is currently a string variable in the form of DDMMYYYY

    I am attempting to create code so that the day of the month is is scrambled with random numbers, with the month and the year remaining unchanged. I am also trying to produce a histogram of the days of the month only (i.e. not using the month or the years values) from the scrambled dates, as evidence of the scrambling.

    Any suggestions would be greatly appreciated.

  • #2
    Try something like the following.

    For your first request take a look at the first two lines of code after the "Begin here" comment. The second part (graphing) follows the second comment.

    .ÿ
    .ÿversionÿ17.0

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿ//ÿseedem
    .ÿsetÿseedÿ521238199

    .ÿ
    .ÿinputÿstr8ÿdeath_date

    ÿÿÿÿÿdeath_d~e
    ÿÿ1.ÿ14102022
    ÿÿ2.ÿ12012020
    ÿÿ3.ÿ31122021
    ÿÿ4.ÿ29022020
    ÿÿ5.ÿend

    .ÿ
    .ÿ*
    .ÿ*ÿBeginÿhere
    .ÿ*
    .ÿgenerateÿintÿdeath_dtÿ=ÿdate(death_date,ÿ"DMY")

    .ÿgenerateÿintÿran_dtÿ=ÿruniformint(firstdayofmonth(death_dt),ÿlastdayofmonth(death_dt))

    .ÿ
    .ÿ*
    .ÿ*ÿForÿhistogram
    .ÿ*
    .ÿgenerateÿintÿran_dayÿ=ÿdatepart(ran_dt,ÿ"day")ÿ//ÿ<=ÿ-histogram-ÿthis

    .ÿ
    .ÿformatÿ*_dtÿ%tdCY-N-D

    .ÿlist,ÿnoobsÿabbreviate(20)

    ÿÿ+------------------------------------------------+
    ÿÿ|ÿdeath_dateÿÿÿÿÿdeath_dtÿÿÿÿÿÿÿran_dtÿÿÿran_dayÿ|
    ÿÿ|------------------------------------------------|
    ÿÿ|ÿÿÿ14102022ÿÿÿ2022-10-14ÿÿÿ2022-10-26ÿÿÿÿÿÿÿÿ26ÿ|
    ÿÿ|ÿÿÿ12012020ÿÿÿ2020-01-12ÿÿÿ2020-01-25ÿÿÿÿÿÿÿÿ25ÿ|
    ÿÿ|ÿÿÿ31122021ÿÿÿ2021-12-31ÿÿÿ2021-12-28ÿÿÿÿÿÿÿÿ28ÿ|
    ÿÿ|ÿÿÿ29022020ÿÿÿ2020-02-29ÿÿÿ2020-02-09ÿÿÿÿÿÿÿÿÿ9ÿ|
    ÿÿ+------------------------------------------------+

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .

    Comment

    Working...
    X