DOFOR Loop Question
DOFOR Loop Question
If I write this code:
COMPUTE X = PORT941NA(2007:12)
DISPLAY X
I get what I expect:
1041.50000
If I place it inside a DOFOR loop:
DOFOR JJ = PORT941NA PITT342NA MINN427NA CHIC917NA AUST448NA PHOE004NA DENV708NA NASH947NA OKLA440NA
COMPUTE X = JJ(2007:12)
DISPLAY X
END DOFOR JJ
I get this:
## SX17. Missing Operator or Adjacent Operands
>>>> COMPUTE X = JJ(<<<<
So I can I identify just one entry in the DOFOR loop?
Thank you!
COMPUTE X = PORT941NA(2007:12)
DISPLAY X
I get what I expect:
1041.50000
If I place it inside a DOFOR loop:
DOFOR JJ = PORT941NA PITT342NA MINN427NA CHIC917NA AUST448NA PHOE004NA DENV708NA NASH947NA OKLA440NA
COMPUTE X = JJ(2007:12)
DISPLAY X
END DOFOR JJ
I get this:
## SX17. Missing Operator or Adjacent Operands
>>>> COMPUTE X = JJ(<<<<
So I can I identify just one entry in the DOFOR loop?
Thank you!
Re: DOFOR Loop Question
By default, the DOFOR index is an INTEGER, which in this case will run over the "handles" for the series. To pull out an entry from a series you need to add a "cast" to the SERIES type:
COMPUTE X = ([series]JJ)(2007:12)
COMPUTE X = ([series]JJ)(2007:12)