Page 1 of 1
Count number of series loaded into memory
Posted: Wed Aug 22, 2012 7:52 pm
by andrewsalter
Hello,
Is there any command or code that allows one to count the number of series that have been read into memory?
I am asking in the context of writing a program for a seasonal adjustment loop. But for use with many different data sets.
Currently I have the following, but would like to replace the ?????? with something.
dofor i = 1 to ?????
x11(mode=multi,adjusted=%s(%l(i)+'_sa'),factors=%s(%l(i)+'_sf')) %s(%l(i))
end dofor
Andrew.
Re: Count number of series loaded into memory
Posted: Wed Aug 22, 2012 9:03 pm
by andrewsalter
I should mention that the last series will have a different label associated with it each time a different dataset is read into memory.
Re: Count number of series loaded into memory
Posted: Thu Aug 23, 2012 9:21 am
by moderator
One way to do it is to use the SCRATCH command, which is normally used to create series by number. The last parameter on SCRATCH can be used to save the number one less than that of the first new series created, so if you tell it to create zero series:
scratch 0 / count
The variable "count" will contain the number of series that already existed.
Not that we generally recommend using arrays of series for this sort of thing, rather than relying on loops over series numbers, but the suggest above should work for you.
Regards,
Tom Maycock
Estima
Re: Count number of series loaded into memory
Posted: Thu Aug 23, 2012 12:11 pm
by TomDoan
With 8.10, you can use the %SLIKE function at any time to get a "snapshot" of the handles for the series in memory (not including CONSTANT and %RESIDS that are created by the program).
compute mylist=%slike("*")
will match any name. %slike("A*") will get all the series which start with A.
compute mylist=%slike("*")
dofor i = mylist
x11(mode=multi,adjusted=%s(%l(i)+'_sa'),factors=%s(%l(i)+'_sf')) %s(%l(i))
end dofor
If you did %SLIKE("*") after the loop, you would catch all the _sa and _sf series as well, so you want to pick the correct time to do it. MYLIST is a VECT[INTEGER] and you can get the number of elements with %SIZE(MYLIST) or %ROWS(MYLIST).
Re: Count number of series loaded into memory
Posted: Mon Aug 27, 2012 1:08 am
by andrewsalter
Thank you kindly, that works well
