DATA Step, Macro, Functions and more

troubleshooting call execute error

Reply
Contributor
Posts: 47

troubleshooting call execute error

hi all,

rsubmit;
%macro get_calcs(time);
gross_combined_ratio_&time.=(inc_&time.+comearn_&time.)/earn_&time.;
%mend;

data mydata ;
set ba_summary;
array time_interval{4}$ 10 ('month','month3','annual','ytd');
do i=1 to 1;
call execute('%get_calcs('||time_interval{i}||')'); end;
*%get_calcs(month);
run;
endrsubmit;

after running the code i get the error:

NOTE: Line generated by the CALL EXECUTE routine.
12 + gross_combined_ratio_month=(inc_month+comearn_month)/earn_month;
--------------------------
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

any sugestions?

Thanks,
sachin
Valued Guide
Posts: 632

Re: troubleshooting call execute error

The CALL EXECUTE routine is used to pass text to a code stack. The stack, in this case a macro call, is then executed AFTER the DATA step has finished execution. This is, of course not helpful to your cause.

Your solution will be to tackle this problem a bit differently. There are several approaches to list processing with the macro language. See the following paper by Ron Fehd for more information.
http://caloxy.com/papers/72Lists.pdf

The four values in your fixed array are the elements of the macro list. You will process across that list, building the assignment statement for each element using a %DO loop of one form or another.
Art
Contributor
Posts: 47

Re: troubleshooting call execute error

hi artc,

Is it possible to elaborate a bit further. I am new to SAS so finding it a bit difficult.

Basically in my case is it not possible to use 'call execute'? does having retain in the data step help at all?

Any suggestions would be welcome.
Thanks,
Sachin
Frequent Contributor
Posts: 127

Re: troubleshooting call execute error

Hi Sachin,

I don't know if this is what you are really expecting but I've created the following sample program in order to show what are the possibilities.



%macro get_calcs(time_interval, cnt_intervals);
%global %quote(&cnt_intervals);
%local word;
%let %quote(&cnt_intervals)=1;
%let word=%qscan(&time_interval,&&&cnt_intervals,%str( ));
%do %while(&word ne);
%global word&&&cnt_intervals;
%let word&&&cnt_intervals = &word;
%*put %superq(word&&&cnt_intervals);
%let %quote(&cnt_intervals)=%eval(&&&cnt_intervals+1);
%let word=%qscan(&time_interval,&&&cnt_intervals,%str( ));
%end;
%let %quote(&cnt_intervals)=%eval(&&&cnt_intervals-1);
%*put "&time_interval" contains &&&cnt_intervals words.;

data test;
set dummy;

%do i=1 %to &&&cnt_intervals.;
gross_combined_ratio_%left(&&word&i) = (inc_%left(&&word&i) + comearn_%left(&&word&i)) / earn_%left(&&word&i);
%end;
run;
%mend get_calcs;


data dummy;
inc_month = 1;
inc_month3 = 2;
inc_annual = 3;
inc_ytd = 4;

comearn_month = 5;
comearn_month3 = 6;
comearn_annual = 7;
comearn_ytd = 8;

earn_month = 2;
earn_month3 = 2;
earn_annual = 2;
earn_ytd = 2;
run;

%get_calcs(month month3 annual ytd, cntWrd);



I hope it helps.

Regards,
Florent
Ask a Question
Discussion stats
  • 3 replies
  • 147 views
  • 0 likes
  • 3 in conversation