Adding New Case

Discussion in 'SPSS' started by Max Jasper, Dec 15, 2011.

  1. Max Jasper

    Max Jasper Guest

    Hi Folks,

    I wish to write syntax SPSS v20 to add new cases to the end of an existing date variable as many as number of days in the following month after the last day in date variable.

    Example:

    var1:
    2011/12/14
    2011/12/15

    Syntax to make

    var1:
    2011/12/14
    2011/12/15
    2011/12/16
    2011/12/17
    .....
    .....
    2011/12/31

    Thanks for your comments and help.

    Max.
     
    Max Jasper, Dec 15, 2011
    #1
    1. Advertisements

  2. Max Jasper

    David Guest

    data list / mydate (SDATE).
    begin data
    2011/12/14
    2011/12/15
    end data.

    COMPUTE @=1.
    MATCH FILES / FILE * / BY @ / [email protected]@.
    *NOTES: 13 is perfectly VALID argument for DATE.MDY (year increments
    by 1).
    * 86400 is the number of seconds in one day.
    DO IF @@.
    + LOOP D=mydate+86400 TO DATE.MDY(XDATE.MONTH(mydate)
    +1,1,XDATE.YEAR(Mydate))-86400 BY 86400.
    + XSAVE OUTFILE "C:\TEMP\DATEFILL.SAV" / RENAME (D Mydate=Mydate
    @@@) / DROP @ @@ @@@.
    + END LOOP.
    END IF.
    ADD FILES / FILE * / FILE "C:\TEMP\DATEFILL.SAV" / DROP @ @@ D.
    LIST.

    MYDATE

    2011/12/14
    2011/12/15
    2011/12/16
    2011/12/17
    2011/12/18
    2011/12/19
    2011/12/20
    2011/12/21
    2011/12/22
    2011/12/23
    2011/12/24
    2011/12/25
    2011/12/26
    2011/12/27
    2011/12/28
    2011/12/29
    2011/12/30
    2011/12/31


    Number of cases read: 18 Number of cases listed: 18
     
    David, Dec 15, 2011
    #2
    1. Advertisements

  3. Max Jasper

    Max Jasper Guest

    Dear David,

    I am so very much grateful to you for your time and SPSS syntax knowledge that shared. Indeed: I love you...and thanks a lot.

    Max.
     
    Max Jasper, Dec 16, 2011
    #3
  4. Max Jasper

    Max Jasper Guest

    Running syntax with MATCH FILE command

    I am noticing the following issue with SPSS 20:
    1) 2nd run does not work unless MATCH FILE temp file is deleted 1st
    2) temp file cannot be deleted unless data file is saved 1st
    3) each subsequent run creates new temp files of double the size of previous run
    4) to run normally, SPSS20 must be closed and reopened 1st

    Max.
     
    Max Jasper, Dec 16, 2011
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.