Opening a data file within a dofor loop

For questions and discussion related to reading in and working with data.

Opening a data file within a dofor loop

Postby cap » Mon Sep 22, 2008 5:27 pm

Hello,

I am trying to open a data file within a dofor loop. When I run the code outside of a loop, it works fine, but when it is inside the loop, upon my first attempt to use one of the variables from the file, i get the syntax error message "##SX11 Identifier is not recognizable"


--------------------------------------------
declare string str
dofor str = "aaa" "bbb" "ccc"


open data "C:\myfile.xls"
data(format=xls,org=columns)
close

print 1 5 var1
## SX11. Identifier var1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>print 1 5 var1<<<<


end dofor str_mo
## SX21. A END or } Here is Unneeded or Unexpected

--------------------------------------------------------------------

Thanks in advance,
-CP
cap
 
Posts: 10
Joined: Thu Aug 14, 2008 2:32 pm

Re: Opening a data file within a dofor loop

Postby TomDoan » Tue Sep 23, 2008 9:49 am

cap wrote:Hello,

I am trying to open a data file within a dofor loop. When I run the code outside of a loop, it works fine, but when it is inside the loop, upon my first attempt to use one of the variables from the file, i get the syntax error message "##SX11 Identifier is not recognizable"


--------------------------------------------
Code: Select all
declare string str
dofor str = "aaa" "bbb" "ccc"


   open data "C:\myfile.xls"
   data(format=xls,org=columns)
   close

   print 1 5 var1
## SX11. Identifier var1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>print 1 5 var1<<<<


end dofor str_mo
## SX21. A END or } Here is Unneeded or Unexpected


Thanks in advance,
-CP


If the DATA instruction were outside of a loop, the VAR1 would be created by the DATA instruction before it was needed by the PRINT. Inside the loop, however, the DATA won't be executed until the loop is run, and the PRINT needs to be interpreted before that can happen. At that point, VAR1 isn't defined. Since you apparently know what (at least some of the) series are going to be created, you can avoid this problem by putting

Code: Select all
DECLARE SERIES VAR1 (and any others you might need)


before the DOFOR instruction.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Postby cap » Tue Sep 23, 2008 10:31 am

It works great now, thanks very much for your help.
cap
 
Posts: 10
Joined: Thu Aug 14, 2008 2:32 pm


Return to Data: Reading, Writing, Transforming

Who is online

Users browsing this forum: Google [Bot] and 0 guests