Page 1 of 1

Troubles with @datestr

Posted: Fri Mar 01, 2013 2:37 pm
by thaigrrr
Good afternoon,

I have, what seems to be a simple issue, but may be Friday brain-block is preventing me from seeing a solution. The code

Code: Select all

%rec_end = "2012:1" ' smpl %rec_end %ols_stop !nQtr = @obssmpl for !q = 1 to !nQtr %ols_stop = @datestr(@dateval(%rec_end)+!q-1, "yyyy:q")) show %ols_stop next
fails to show the next value for %ols_stop, but if I remove ", "yyyy:q"" from it shows the new value (just not in the format that I want.)

I can't see the mistake, since the code above is adapted from another code I've written:

Code: Select all

%rec_end = "2012:1" ' %rec_start = %ols_stop smpl %rec_end %rec_start !nQtr = @obssmpl for !q = 1 to (!nQtr) %rec_start = @datestr(@dateval(%ols_stop)-!q+1, "yyyy:q") next
The second code works fine. The difference between them, in theory, is that the first one adds a quarter to each loop, while the second code subtracts from each loop.

My feeling is that the solution is very simple, but my eyes are crossed and I just can't see what's wrong.

Thank you for any suggestions/help.

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 2:59 pm
by EViews Gareth
Too many close parenthesis in the first one.

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 3:15 pm
by thaigrrr
I removed the extra parenthesis, but that didn't seem to fix the issue and %ols_stop is still not being updated.

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 3:35 pm
by EViews Gareth
You're probably just not moving through any quarters. Since you're displaying the date in quarter format, it will only change once you move from one quarter to another.

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 3:43 pm
by thaigrrr
The weird thing is if I include "show !q" right before the line, then I can see !q is being looped through. %ols_stop just doesn't update.

What gets me is that if I remove the format in @datestr, then the line loops fine. It boggles me why it wouldn't move through the quarter when I only revised it slightly from the original code :cry:

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 3:52 pm
by EViews Gareth
My point is that !q is looping, but just not far enough.

If the first time through the loop, you're dealing with January 1st 2012, then %ols_start will be "2012:1".
The second time through the loop, you're dealing with January 2nd 2012, then %ols_start will be "2012:1".
The third time through the loop, you're dealing with January 3rd 2012, then %ols_start will be "2012:1"

and so on...

It would take 100 (roughly) runs through the loop before the quarter changed.

Re: Troubles with @datestr

Posted: Fri Mar 01, 2013 4:03 pm
by thaigrrr
Ah... I see what you mean now, but I still don't see why it works in the second code but not in the first...

Do you think the order of the variables within @datestr matters? I think when I moved them around to @dateval(%rec_end)-1+!q, I got it to loop through twice. Not exactly the final result I wanted, but an improvement of some sort.

I'll just leave this as unsolved mystery and use the second code with modifications into what I want. I really appreciate your replies on this, Gareth.