SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 


#Analytics
#SPSSStatistics
#Analyticstools
 View Only
  • 1.  Need to Create Duplicate Cases

    Posted 07/09/21 01:37 PM
    Hi, 

    I have a list of Student ID numbers in dataset A. In another dataset B, I have a list of distinct courses. I wish to create a third dataset C that repeats each course for each student ID. For example:

    dataset A: (student IDs)
    16584
    13244
    12349

    dataset B: (courses)
    MATH101
    BIO101
    CHEM101
    SOC101

    desired dataset C:
    16584 MATH101
    16584 BIO101
    16584 CHEM101
    16584 SOC101
    13244 MATH101
    13244 BIO101
    13244 CHEM101
    13244 SOC101
    12349 MATH101
    12349 BIO101
    12349 CHEM101
    12349 SOC101

    In essence, I wish to duplicate the list of courses (data set B) for each of the student Ids (dataset A). I have tens of thousands of records, so doing so with syntax is preferred! Is there a way to accomplish this? 


    Lauren

    ------------------------------
    Lauren Fuhrman
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Need to Create Duplicate Cases

    Posted 07/09/21 01:54 PM
    The easiest way to do this is with the STATS CARTPROD extension command.  You can install that via the Extensions > Extension Hub menu.

    Then run code like the following, replacing the data definitions below as appropriate.

    data list list/id(a5).
    begin data
    16584
    13244
    12349
    end data.
    dataset name a.

    data list list/courses(a8).
    begin data
    MATH101
    BIO101
    CHEM101
    SOC101
    end data.
    dataset name b.
    dataset activate a.

    DATASET ACTIVATE a.
    STATS CARTPROD VAR1=id INPUT2=b VAR2=courses 
    /SAVE OUTFILE="r:\ibm\users\fuhrman\product.sav".

    --