BookmarkSubscribeRSS Feed
SachinRuk
Calcite | Level 5
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
3 REPLIES 3
ArtC
Rhodochrosite | Level 12
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
SachinRuk
Calcite | Level 5
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
Florent
Quartz | Level 8
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 894 views
  • 0 likes
  • 3 in conversation