Syntax - Generate new variable conditional to values of other variables

#1
Hi everyone!

I'm a sociology student and I am a SPSS beginner. I need some help with the syntax, I already looked around but I can't find how to do what I need.
I have a data set that roughly looks as the one in the attached picture. I need to generate a new variable that contains, for each user (ID) the hour and the date only referred to one of the questions.
For example: I want to compute a new variable, TIME_Q1, in which the value is "11.04 1/10/2019"
for the user 1 (ID =1), "15.07 04/09/2019" for the user 2 (ID =2) and so on. Can anyone help me with the syntax?

Also, my DATE variable is nominal and when I run "alter type" to change it into a date, all the values become ".". May it be because in front of the each value there are brackets " (see picture)? This does not happen when I alter the type of the HOUR variable that is nominal and has brackets as well.

Any suggestion is more than welcome!

1599637417586.png
 

Karabiner

TS Contributor
#2
If the data are sorted as seen in your image, and you need the contents of the first question, then you can use the function aggregate with break variable "id", and you request the first value from variable "question" within each id to be written into the new variable.

What the exact problem with "date" is, I don't know, but you could copy that variable, paste it into a word processor, remove the brackets, and copy&paste it back.

With kind regards

Karabiner
 
#3
you request the first value from variable "question" within each id to be written into the new variable.
Dear Karabiner,

Thank you very much for your quick answer!
Still I don't understand how to write the second part of the syntax as you are suggesting. Could you please help me to understand?

All the best,

Marla
 

Karabiner

TS Contributor
#4
You can use the drop-down menue data > aggregate.
You can indicate the break variable there, and which
statistics you want to obtain.

With kind regards

Karabiner
 
#5
Dear Karabiner,

Thanks for your reply.
I was able to compute a variable "TIME" with DATE and HOUR. I used the command aggregate as you suggested and it works fine for the first and the last values of time. Here is the syntax that I am using:

aggregate OUTFILE *
/PRESORTED
/BREAK = id
/TIME_Q1 = FIRST (TIME).

This works for the time of Q1 (variable "question"), and for the last one if I use the function "last". However, I do not understand what I should do if I need the second value (referred to Q2). My actual data set is wider than this one (there are many more questions for which I have to generate a corresponding time variable). Are you aware if there is a way in which I can do it? Like, if QUESTION = Q2 then TIME_Q2 =TIME.
Anyway, you really helped me to understand the process, thank you very much for your time.

Best,
Marla

P.s. For anyone having my same issue with altering the type of the DATE variable (see first post), deleting the brackets worked for me.
 

Karabiner

TS Contributor
#6
You can compute a neue variable which contains the value 1 if question is q2. Then you sort your file using id and the new variable. Then you use aggregate.

With kind regards

Karabiner