Hi Cameron.
This is a timing issue : the CALL EXECUTE statement just stores code in memory, and executes the whole bunch of stored code after the end of the Data step.
What you would like here is your macro-program to execute within the Data step. It will not. In fact, even if you changed the code to have %GetCode execute for each observation, it would not write anything correct in the output data set, because your macro is SQL, and it cannot be run within the Data step. Remember that macro is just copy & paste ! So if you run %getCode, that means that you execute the proc Sql ... statements just at the time the %getCode statement is read.
I think you could come to an answer without macro coding. Something like that (not tested) :
[pre]
DATA work.testCallExecute (KEEP=start_pos code_block) ;
SET work.progparse2 ;
BY start_pos ; /* keep track of changing values for start_pos (dataset must be sorted beforehand */
RETAIN code_block ; /* store values in memory from an observation to the following */
LENGTH code_block $ 500 ;
FORMAT code_block $500.;
IF FIRST.start_pos THEN code_block="" ; /* initialize */
code_block=COMPBL(code_block!!" "!!progText!!";") ; /* build up values */
IF LAST.code_block THEN OUTPUT ; /* write when done */
RUN ;
[/pre]
Regards,
Olivier