by moderator » Thu Aug 19, 2010 9:42 am
If you want to the DATA instructions in a loop, so that the series variables are replaced each time by the new data, I would recommend using DISPLAY instructions to build up the SQL string into a variable, then use that variable as the argument for the SQL option.
For example, suppose you have N area codes, and fill a vector of labels called AREA with the codes. You can do something like:
compute prefix = "select date, value as URU from la_msa_all_data where area_code = "
compute suffix = "and measure_text like '%rate' order by date"
do c=1,n
compute sqlstring = prefix+&area(c)+suffix
data(format=odbc,sql=sqlstring)
...
end do
where the & character tells RATS to take the value stored in AREA(c). As a check, you may want to star by doing something like:
compute c = 1
compute sqlstring = prefix+&area(c)+suffix
display sqlstring
to make sure the string is correct.
If you instead want to read in all the data at once (i.e. into separate series for each area code), you could use a similar approach, looping over DISPLAY with a UNIT option to write each line (as part of a long sequence of SQL commands) to an external text file. You can then open the SQL string file and process the whole sequence using the QUERY option to refer to the unitname used when opening the SQL file:
OPEN SQLINPUT SQL.TXT
OPEN ODBC "BLIS2"
DATE(FORMAT=ODBC,QUERY=sqlinput)
Regards,
Tom Maycock