Count number of series loaded into memory

For questions that don't fall into one of the categories above, such as working with the RATS interface, using Wizards, etc.
andrewsalter
Posts: 3
Joined: Fri Aug 10, 2012 1:05 am

Count number of series loaded into memory

Unread post 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.
andrewsalter
Posts: 3
Joined: Fri Aug 10, 2012 1:05 am

Re: Count number of series loaded into memory

Unread post 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.
moderator
Site Admin
Posts: 269
Joined: Thu Oct 19, 2006 4:33 pm

Re: Count number of series loaded into memory

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

Re: Count number of series loaded into memory

Unread post 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).
andrewsalter
Posts: 3
Joined: Fri Aug 10, 2012 1:05 am

Re: Count number of series loaded into memory

Unread post by andrewsalter »

Thank you kindly, that works well :)
Post Reply