Hello,
The immediate issue with your code is that you've created string objects (
ss0,
ss1,
ss2) but later used string variables (
%ss0,
%ss1,
%ss2). Those non-existant variables will be treated as NAs by @eqna, thus your first if statement conditional will always be true and
temp will always be assigned
mat01.
After fixing that issue, the next issue you'll find is that @pagesmpl returns an upper-case string while your sample strings are lower-case, thus none of your if statement conditionals will be true. That's easy to fix by changing the q's in your samples to Q's, or by using @upper elsewhere in your code.
However, regarding simplifying your code, there are some ways you could completely eliminate the if statements. If you'll always iterate through your samples in a consistent order you can make the assignment to
temp dependent on an iteration number rather than the current sample. For example,
Code: Select all
%sample1 = "1999Q1 2001q4"
%sample2 = "2002Q1 2004q4"
!i = 1
for %1 %2 {%sample1} {%sample2}
%tmp = @str(!i, "i02")
matrix temp = mat{%tmp}
!i = !i + 1
next
The above code assumes that the matrices you're assigning from are regularly named (
mat01,
mat02, etc.), but you can just as easily use a list of arbitrary matrix names. For example,
Code: Select all
%sample1 = "1999Q1 2001q4"
%sample2 = "2002Q1 2004q4"
%mats = "mat01 mat02"
!i = 1
for %1 %2 {%sample1} {%sample2}
%tmp = @word(%mats, !i)
matrix temp = {%tmp}
!i = !i + 1
next
There may be other, better ways to organize the for loop based on the work your program will perform, but the above are some starting points.