Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning Values in SPSS using a Reference Variable

I am having some difficulty achieving the following functionality in SPSS. I'm trying to come up with a way to track pets admitted to a clinic with a certain disease. Originally the pets are assigned a certain number if they have this disease, but in subsequent visits this number is 0, since their disease will be cured! But, we want to see how the pets are doing so we want to be able to add a variable (past disease) that achieves the following functionality.

NAME    Visit DATE    Disease Code    
SPOT     1/1              1                 
SPOT     1/9              0                  
SPOT     1/11             0        
Bruno    12/1             1                  
Bruno    12/8             0                           

In this example, Spot and Bruno came in for Disease 1, but they didn't have disease 1 when they came back, since the treatment worked. But, we want to add a variable that still shows that Spot and Bruno had the disease. So the expected outcome would be this:

NAME    Visit DATE    Disease Code    Past Disease Code 
SPOT     1/1              1                  1
SPOT     1/9              0                  1
SPOT     1/11             0                  1
Bruno    12/1             1                  1
Bruno    12/8             0                  1

I attempted to do this by using an IF loop, but I couldn't quite get the syntax right, here since Spot and Bruno are entered as a a case multiple times, instead of as a single case. Does that make sense? Essentially, I want to be able to say that since SPOT and Bruno had a 1 for the variable "Disease code", the "Past disease code" should equal 1 for every entry of Spot and Bruno. Note that we can assume that every dog has a different name.

like image 527
George Avatar asked Jun 26 '26 02:06

George


1 Answers

Look up the AGGREGATE command.

Depending on your data something like this might work, nonetheless should suffice as a good example of how the command works.

AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK=name /PastDiseaseCode=MAX(DiseaseCode).
like image 174
Jignesh Sutar Avatar answered Jul 01 '26 10:07

Jignesh Sutar