SPSS Statistics

 View Only
  • 1.  Adding New Cases via Syntax

    Posted Thu June 02, 2022 09:24 AM
    Hello! I am working with an RCT study in which patients are asked to report on a number of variables each week. Patients are on a rolling enrollment and have a range of data from new admits with just one week of info, to patients with as many as 40 weeks of info.

    The issue I'm having is, we are missing some weeks of data for a number of patients- but it's not consistent. For example, for Patient 145, we have Weeks 1,2,4,& 5, but they are missing Week 3. For Patient 600, we have Weeks 1,2,3,4,5,6,7,8, 10, 12, 14 (so we are missing Weeks 9, 11,13).

    I have a variable that denotes the week's number and if it has jumped more than 1 (going from Week 1 to 2 is a jump of 1, so anything other than 1 is missing a week of data). How can I use syntax to recognize if this number is 2 (the data is missing a week from the entry prior), go up a row in the data and insert a blank case? Or, if that number is 3 (a jump of 3 weeks from the entry to the next), can it insert two cases above that week for the two missing weeks of data, etc.

    I'm happy to go back and insert data once the blank case is there, but with 6000 cases (and more added each month), this task is tedious to do by hand over and over. Thanks!

    ------------------------------
    emily b
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Adding New Cases via Syntax

    Posted Thu June 02, 2022 12:39 PM
    Hi, Emily.

    If the number of weeks is known (say, 14), and there must be 14 rows for each patient, then I would set up a "dummy" dataset with nothing but a patient number and week number. 6000 rows in all, 2 variables only, no missing data.

    Then I'd use the MATCH FILES procedure and match that dataset to the one with missing data(also sorted by patient and week).

    If you want an example I will code and send one.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: Adding New Cases via Syntax

    Posted Fri June 10, 2022 01:19 PM
    Thank you for your help, Rick! I had read that was probably the best route to go, so it was nice to hear that supported.

    I created a dataset for 600 P's, and 60 weeks per patient. The strange thing that's happening now, is I need to merge the "Original" dataset with the "Template" dataset based on their ID number and week number, but when I go to merge, it creates about 30 rows of empty cases (they have no ID number, but they have a week number, and I have no idea where they came from and if they have messed with the rest of the data).

    I've searched high and low why this may be happening, and I can't get it to stop. Do you happen to have a syntax that tells SPSS to merge on two variables (ID and WEEK), merging the "Original" into the "Template?" Thanks!

    ------------------------------
    emily bmn
    ------------------------------



  • 4.  RE: Adding New Cases via Syntax

    Posted Fri June 10, 2022 01:40 PM
    Hi, Emily. Here is an example that might help.
    ** First, both files must be sorted by ID and WEEK.
    GET FILE TemplateFileNameHere.
    SORT CASES BY ID (A) WEEK (A).
    DATASET NAME Template.
    
    GET FILE OriginalFileNameHere.
    SORT CASES BY ID (A) WEEK (A).
    DATASET NAME Original.
    
    ** Then, match them.
    MATCH FILES /FILE=Template /FILE=Original /IN=FromOriginalFile /BY ID WEEK.​

    At least now you have a binary variable (FromOriginalFile) telling you which row came from which dataset (1 if from the original file, 0 if from the template).

    You can always discard cases with no ID. 

    SELECT IF NOT(MISSING(ID)).
    EXECUTE.


    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 5.  RE: Adding New Cases via Syntax

    Posted Fri June 17, 2022 08:40 PM
    Thank you again, Rick!
    Hopefully one more question for you:

    I have created my final data file with 100 weeks of data per patient and 600+ patients. Within the set, we have a variable of "alert" (0 = no alert, 1 = alert) where the pt has alerted their medical team. We are trying to understand the symptoms 2 weeks leading up to an alert, the week of the alert itself, and the two weeks after the alert. If they have data for weeks 1,2,3,4,5 and alert on week 3, in the line for week 5, we have pulled forward all the data from each week to have five weeks of data in one line (weeks 1,2,3,4,5 symptoms are now all in week 5's line). 

    Where I'm struggling now is, I need to create a variable that takes each line, looks back two weeks to see if there was an alert, and if so, create a new variable, "AlertVector." While I have a separate variable telling me if each individual week alerted, I don't know how to tell SPSS to take each line, check two weeks before, and IF they alerted two weeks prior, code AlertVector as a "1," and if there was no alert two weeks prior, code as a "0." In some cases, that might be weeks 1,2,3(alert),4,5; in others it may be weeks 15,16,17(alert),18,19.

    It seems simple-ish, but syntax keeps yelling at me. 
    Thanks in advance, Rick! Have a nice wknd!
    EB


    ------------------------------
    emily bmn
    ------------------------------



  • 6.  RE: Adding New Cases via Syntax

    IBM Champion
    Posted Fri June 17, 2022 09:58 PM
    What you need is the lag function in an IF statement.

    --





  • 7.  RE: Adding New Cases via Syntax

    Posted Mon June 20, 2022 11:27 AM
    Emily;

    Is this what you had in mind?

    data list free /pt week alert. 
    begin data. 
    1 1 0 
    1 2 0 
    1 3 1 
    1 4 0 
    1 5 0 
    end data. 
     
    compute AlertVector=lag(alert,2). 
    list.​


    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------