• Aggregate and count by date syntax help

    From Bruce Weaver@21:1/5 to Rich Ulrich on Thu Jun 6 07:54:44 2019
    On Thursday, June 6, 2019 at 12:23:19 AM UTC-4, Rich Ulrich wrote:
    On Tue, 4 Jun 2019 14:20:35 -0700 (PDT), Bruce Weaver
    <bweaver@lakeheadu.ca> wrote:

    On Tuesday, June 4, 2019 at 1:26:53 PM UTC-4, Rich Ulrich wrote:

    --- snip ---
    I read the example differently. Isn't it asking for this?

    RANK DATEvar by IDvar into Session.

    --
    Rich Ulrich

    Right you are, Rich--although INTO doesn't appear to work with RANK.

    NEW FILE.
    DATASET CLOSE ALL.
    DATA LIST LIST / ID (F1) Date(date) x(F1).
    BEGIN DATA
    1 02/01/2018 2
    1 02/10/2018 3
    1 04/04/2017 1
    2 01/10/2015 1
    2 03/04/2016 2
    END DATA.

    RANK VARIABLES=Date (A) BY ID.
    RENAME VARIABLES (Rdate=Session).
    FORMATS Session(F2.0).
    LIST.
    * x = desired result, Session = obtained result.

    OUTPUT from LIST:

    ID Date x Session

    1 02-JAN-2018 2 2
    1 02-OCT-2018 3 3
    1 04-APR-2017 1 1
    2 01-OCT-2015 1 1
    2 03-APR-2016 2 2


    Number of cases read: 5 Number of cases listed: 5

    Well, INTO is available. I got INTO from the syntax manual,
    but I didn't go far enough to get reminded of the complication.


    The proper syntax seems to be,

    RANK Datevar by IDvar/ rank into Session.

    The second "rank" -- "rank into" -- is parsed as
    <function> INTO

    where a set of functions is available, as documented at https://www.ibm.com/support/knowledgecenter/en/SSLVMB_24.0.0/spss/base/syn_rank_function.html#syn_rank_function

    "The functions assign default names to the new variables unless
    keyword INTO is specified."

    --
    Rich Ulrich

    Well done, Rich. That does it. Here is the revised syntax for the complete example.

    NEW FILE.
    DATASET CLOSE ALL.
    DATA LIST LIST / ID (F1) Date(date) x(F1).
    BEGIN DATA
    1 02/01/2018 2
    1 02/10/2018 3
    1 04/04/2017 1
    2 01/10/2015 1
    2 03/04/2016 2
    END DATA.

    RANK VARIABLES=Date (A) BY ID /RANK INTO Session.
    FORMATS Session(F2.0).
    LIST.

    Output from LIST:

    ID Date x Session

    1 02-JAN-2018 2 2
    1 02-OCT-2018 3 3
    1 04-APR-2017 1 1
    2 01-OCT-2015 1 1
    2 03-APR-2016 2 2


    Number of cases read: 5 Number of cases listed: 5

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)