Compare two series with loop
Posted: Thu Apr 12, 2012 8:58 am
Hi all, I got trouble comparing two series with unequal observations. My real data is huge so I just create a trial data to work on that at this moment. As in the picture that I attached, originally I have 5 series Analyst, analyst_1, day, day_1 and value_1.
I want to create a new series called Value that takes value of Value_1 if analyst=analyst_1 and day < day_1. The trouble is the comparison is not row by row. For example, if the first line analyst(1) = analyst_1(1) and day(1) > day_1(1), the program will keep compare the next pair day(1) with day_1(2). If the condition is satisfied ( day(1) < day_1(2)), value(1) will equal value_1(2) or 1.1 as in the pic. So for every pair analyst and analyst_1 equal, each obs in day will be compared to each observation in day_1 correspondingly.
This is the code that I write for this trial data
SERIES value
FOR !i=1 TO @obsrange
FOR !j=1 TO @obsrange
IF analyst(!i)=analyst_1(!j) AND day(!i) <= day_1(!j) THEN value(!i)=value_1(!j)
ENDIF
NEXT
NEXT
It works but if I use it for my real data ( which the no of obs is 120 000), the program takes forever to run. I am just wondering if there is a more elegant way to do this.
I am really appreciated if anyone could help.
I want to create a new series called Value that takes value of Value_1 if analyst=analyst_1 and day < day_1. The trouble is the comparison is not row by row. For example, if the first line analyst(1) = analyst_1(1) and day(1) > day_1(1), the program will keep compare the next pair day(1) with day_1(2). If the condition is satisfied ( day(1) < day_1(2)), value(1) will equal value_1(2) or 1.1 as in the pic. So for every pair analyst and analyst_1 equal, each obs in day will be compared to each observation in day_1 correspondingly.
This is the code that I write for this trial data
SERIES value
FOR !i=1 TO @obsrange
FOR !j=1 TO @obsrange
IF analyst(!i)=analyst_1(!j) AND day(!i) <= day_1(!j) THEN value(!i)=value_1(!j)
ENDIF
NEXT
NEXT
It works but if I use it for my real data ( which the no of obs is 120 000), the program takes forever to run. I am just wondering if there is a more elegant way to do this.
I am really appreciated if anyone could help.