DOFOR Loop Question

For questions and discussion related to reading in and working with data.
timduy
Posts: 50
Joined: Sun Jan 15, 2012 12:24 am

DOFOR Loop Question

Unread post by timduy »

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!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR Loop Question

Unread post by TomDoan »

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)
timduy
Posts: 50
Joined: Sun Jan 15, 2012 12:24 am

Re: DOFOR Loop Question

Unread post by timduy »

Again, thank you!
Post Reply