PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, December 18, 2022

[FIXED] How to extract last variables' name and time, and after change all variables to missing?

 December 18, 2022     spss, syntax     No comments   

Issue

Let's say I have the following example, with no mandatory questions:

enter image description here

I want to calculate "time_end" and variable's name for "time_end" ("x1") - blue cells.

It would be something like this:

time_end = time of last answered/seen question

x1 = last answered/seen question

All variables AFTER "x1" should then be equal to missing (no answer) and not to "zero".

One of the references to detect these situation, could be that the "time_var" is empty, so no more answers from that point onward, no? But how?

For the ones who answer everything, it's not a problem (see ID=5).

But when I have "drop outs" (quit in middle of questionnaire, do not finish it), I have a syntax where I wrote every variable, by hand, for each one of these ID cases, including naming all variables to be placed missing after a "drop out" (more that 50...).

Is there a way to automatize this with syntax? Thanks!


Solution

Here is one way to do it-
The following code runs through the variables backwards. The first time it meets a time in a time variable, it puts that time in the "time_end" variable and the varname in the x1 variable. It also cleans the varX along the way:

string x1(a20).
compute time_end=$sysmis.
do repeat tm = time_var6 time_var5  time_var4 time_var3 time_var2 time_var1
         /vr = var6 var5 var4 var3 var2 var1 
         /vrnm = "var6" "var5" "var4" "var3" "var2" "var1" .
   if missing(tm) vr=$sysmis.
   do if missing(time_end) and not missing(tm).
      compute time_end=tm.
      compute x1=vrnm.
   end if.
end repeat.

formats time_end(time8).


Answered By - eli-k
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing