SPSS Macro Command

I need to run below in SPSS:

if (event_duration = 0) Acti_Activity = Activity.
if (event_duration = 1) Acti_Activity = MEAN (Activity, Activity_1).
if (event_duration = 2) Acti_Activity = MEAN (Activity, Activity_1, Activity_2).

... up to...

if (event_duration = 120) Acti_Activity = MEAN 
(Activity, Activity_1, Activity_2, Activity_3, Activity_4, Activity_5, Activity_6, Activity_7, Activity_8, Activity_9, Activity_10, 
Activity_11, Activity_12, Activity_13, Activity_14, Activity_15, Activity_16, Activity_17, Activity_18, Activity_19..... ,Activity_120

Essentially, I need a macro that "If event_duration = X, means Activity variables before Activity_X."

I have to do this on 15 variables, so although I could type them all, I assume there is some code that will simplify it?

+4
source share
2 answers

Here's how to wrap this in a SPA DEFINE- macro ! ENDDEFINE , I parameterized N = 120, but you could also parameterize well for 15 different variables that you need to run for this. I will leave it to you to adapt.

define !RunJob(n=!cmdend)

!do !i = 0 !to !n
    !if (!i=0) !then
        do  if (event_duration = !i).
            compute Acti_Activity =Acti_Activity.
    !ifend
    !if (!i>0) !then
        else if (event_duration = !i).
            compute Acti_Activity =MEAN(Acti_Activity to !concat("Acti_Activity_",!i)).
    !ifend

!doend
end if.      

!enddefine.

set mprint on.
!RunJob n=120.

- , Activity_15 , . , Python Programmability, .

+4

. event_duration 0, , Activity_1 Activity_119 , event_duration 1, , Activity_2 Activity_119 .., - , .

compute Acti_Activity = SUM(Activity to Activity119) / (event_duration + 1).
execute.
0

Source: https://habr.com/ru/post/1585080/


All Articles