Array Syntax for SPSS

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Array Syntax for SPSS

nato123
I am trying to use an array in SPSS but am unsure how to translate the SAS code to SPSS. Can SPSS do arrays?

What I am trying to do is (how it looks is SAS):

arraymktmemos{7} m1, m2, m3, m6, m9, m10, m14; do i=1 to 7;
if mktmemos {i} in (1,2) then countselfm=countselfm+1;
if mktmemos{i} in (3,4) then countotherm=countotherm+1;
etc. etc.

....

end;

Thanks!
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Array Syntax for SPSS

Buhi, Eric
Banned User
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Array Syntax for SPSS

Rich Ulrich
In reply to this post by nato123
I haven't gotten that fancy in SAS, but it looks to me
like you just want to use the COUNT command.

COUNT  countselfm= m1, m2, m3, m6, m9, m10, m14(1,2) .
COUNT  countotherm= m1, m2, m3, m6, m9, m10, m14(3,4) .

--
Rich Ulrich

> Date: Mon, 28 May 2012 21:50:57 -0700

> From: [hidden email]
> Subject: Array Syntax for SPSS
> To: [hidden email]
>
> I am trying to use an array in SPSS but am unsure how to translate the SAS
> code to SPSS. Can SPSS do arrays?
>
> What I am trying to do is (how it looks is SAS):
>
> arraymktmemos{7} m1, m2, m3, m6, m9, m10, m14; do i=1 to 7;
> if mktmemos {i} in (1,2) then countselfm=countselfm+1;
> if mktmemos{i} in (3,4) then countotherm=countotherm+1;
> etc. etc.
>
> ....
>
> end;
>
...
Reply | Threaded
Open this post in threaded view
|

Re: Array Syntax for SPSS

David Marso
Administrator
In reply to this post by nato123
SPSS has VECTOR but it requires variables to be contiguous.
DO REPEAT is also useful but Rich's COUNT suggestion is probably the easiest
solution for your specific request).
It the future when posting SAS to SPSS requests please illustrate with sample input data and output so to minimize possible confusion.  I know minimal SAS, but what else could such a sequence be doing ;-)  
In many/most other cases it is unlikely to be so transparent.

DO REPEAT v=m1 m2 m3 m6 m9 m10 m14.
COMPUTE countselfm=SUM( ANY(v,1,2),countselfm).
COMPUTE countotherm=SUM( ANY(v,3,4),countotherm).
END REPEAT.

If M1..M14 are contiguous you could use VECTOR/LOOP mix.
VECTOR v=M1 TO M14.
LOOP #=1 TO 7.
COMPUTE countselfm=SUM( ANY(v(#),1,2),countselfm).
COMPUTE countotherm=SUM( ANY(v(#),3,4),countotherm).
END LOOP.


nato123 wrote
I am trying to use an array in SPSS but am unsure how to translate the SAS code to SPSS. Can SPSS do arrays?

What I am trying to do is (how it looks is SAS):

arraymktmemos{7} m1, m2, m3, m6, m9, m10, m14; do i=1 to 7;
if mktmemos {i} in (1,2) then countselfm=countselfm+1;
if mktmemos{i} in (3,4) then countotherm=countotherm+1;
etc. etc.

....

end;

Thanks!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"