Page 1 of 1

Opening a data file within a dofor loop

Posted: Mon Sep 22, 2008 5:27 pm
by cap
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

Re: Opening a data file within a dofor loop

Posted: Tue Sep 23, 2008 9:49 am
by TomDoan
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.

Posted: Tue Sep 23, 2008 10:31 am
by cap
It works great now, thanks very much for your help.