BookmarkSubscribeRSS Feed
arunrami
Pyrite | Level 9

Hello All,

 

Below is the part of the code which I use to create different data set based on the macro variable 'cnt_crr_saa_limit' value using Do loop but I am getting below error messages. Can any one help me out?

/* Do process only when some records available in cr_saa_rating_benchmrk */
%if &cnt_crr_saa_limit. ne 0 %then
	%Do;
		%do i=1 %to &cnt_crr_saa_limit;

			data grp_bbb_below_&i;
				set work.cr_saa_rating_benchmrk
					(keep=portfolio_name bbb_below_benchmark bbb_below_leeway bbb_below_current_level total_exposure
					rename=(bbb_below_benchmark=benchmark bbb_below_leeway=leeway bbb_below_current_level=current_level)
					firstobs=&i obs=&i);
				length rating $ 50;
				rating = 'BBB & Below';
			run;


			data grp_bb_below_&i;
				set work.cr_saa_rating_benchmrk
					(keep=portfolio_name bb_below_benchmark bb_below_leeway bb_below_current_level total_exposure
					rename=(bb_below_benchmark=benchmark bb_below_leeway=leeway bb_below_current_level=current_level)
					firstobs=&i obs=&i);
				length rating $ 50;
				rating = 'BB & Below';
			run;

			data grp_nr_&i;
				set work.cr_saa_rating_benchmrk
					(keep=portfolio_name nr_benchmark nr_leeway nr_current_level total_exposure
					rename=(nr_benchmark=benchmark nr_leeway=leeway nr_current_level=current_level)
					firstobs=&i obs=&i);
				length rating $ 50;
				rating = 'Not Rated';
			run;

		%end;

ERROR;

74         %if &cnt_crr_saa_limit. ne 0 %then
SYMBOLGEN:  Macro variable CNT_CRR_SAA_LIMIT resolves to        3
75             %Do;
76                 %do i=1 %to &cnt_crr_saa_limit;
                 _
                 180
SYMBOLGEN:  Macro variable CNT_CRR_SAA_LIMIT resolves to        3

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

6 REPLIES 6
andreas_lds
Jade | Level 19

At least an %end statement is missing to close

%if &cnt_crr_saa_limit. ne 0 %then

The following simplification runs without errors. So the problem must be before the code posted.

 

%macro box;
   %if &cnt_crr_saa_limit. ne 0 %then %Do;

      %do i=1 %to &cnt_crr_saa_limit;
         %put &=i;
      %end;
   %end;
%mend;

%let cnt_crr_saa_limit =        3;
options symbolgen mprint mlogic;

%box;
MSMM
SAS Employee

you should use it inside the macro body  in addition to every %if statement should have close %end for example

 

%macro test;

%if &cnt_crr_saa_limit. ne 0 %then    
%Do;
Your CODE
%end;

%mend test ;

%test;

arunrami
Pyrite | Level 9

Here is the actual code, I have declared macro

%macro Info;
proc sql noprint;
		*connect to oracle (user=&ora_user. password="&ora_pw." path=&ora_path.);
		insert into work.cr_saa_rating_benchmrk 
			/*		select * from connection to oracle (*/
		select * from work.A;

		/*	DISCONNECT FROM oracle;*/
	quit;

	/*proc print data=work.cr_saa_rating_benchmrk;*/
	proc sql noprint;
		select count(*) into :cnt_crr_saa_limit from work.cr_saa_rating_benchmrk;
	quit;

	%put #### number of records read from REP_SAA_LIMIT#### &cnt_crr_saa_limit.;

	/* Do process only when some records available in cr_saa_rating_benchmrk */
	%if &cnt_crr_saa_limit. ne 0 %then
		%do;
			%do i=1 %to &cnt_crr_saa_limit;

				data grp_bbb_below_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name bbb_below_benchmark bbb_below_leeway bbb_below_current_level total_exposure
						rename=(bbb_below_benchmark=benchmark bbb_below_leeway=leeway bbb_below_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'BBB & Below';
				run;

				data grp_bb_below_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name bb_below_benchmark bb_below_leeway bb_below_current_level total_exposure
						rename=(bb_below_benchmark=benchmark bb_below_leeway=leeway bb_below_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'BB & Below';
				run;

				data grp_nr_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name nr_benchmark nr_leeway nr_current_level total_exposure
						rename=(nr_benchmark=benchmark nr_leeway=leeway nr_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'Not Rated';
				run;

		%end;
%end;
%mend;
%info;
Kurt_Bremser
Super User

When I run that code as posted, I only get ERRORs from the Base SAS code because of the missing libs/datasets, but NO problem at all with the macro code.

Please post the log from this code as is.


@arunrami wrote:

Here is the actual code, I have declared macro

%macro Info;
proc sql noprint;
		*connect to oracle (user=&ora_user. password="&ora_pw." path=&ora_path.);
		insert into work.cr_saa_rating_benchmrk 
			/*		select * from connection to oracle (*/
		select * from work.A;

		/*	DISCONNECT FROM oracle;*/
	quit;

	/*proc print data=work.cr_saa_rating_benchmrk;*/
	proc sql noprint;
		select count(*) into :cnt_crr_saa_limit from work.cr_saa_rating_benchmrk;
	quit;

	%put #### number of records read from REP_SAA_LIMIT#### &cnt_crr_saa_limit.;

	/* Do process only when some records available in cr_saa_rating_benchmrk */
	%if &cnt_crr_saa_limit. ne 0 %then
		%do;
			%do i=1 %to &cnt_crr_saa_limit;

				data grp_bbb_below_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name bbb_below_benchmark bbb_below_leeway bbb_below_current_level total_exposure
						rename=(bbb_below_benchmark=benchmark bbb_below_leeway=leeway bbb_below_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'BBB & Below';
				run;

				data grp_bb_below_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name bb_below_benchmark bb_below_leeway bb_below_current_level total_exposure
						rename=(bb_below_benchmark=benchmark bb_below_leeway=leeway bb_below_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'BB & Below';
				run;

				data grp_nr_&i;
					set work.cr_saa_rating_benchmrk
						(keep=portfolio_name nr_benchmark nr_leeway nr_current_level total_exposure
						rename=(nr_benchmark=benchmark nr_leeway=leeway nr_current_level=current_level)
						firstobs=&i obs=&i);
					length rating $ 50;
					rating = 'Not Rated';
				run;

		%end;
%end;
%mend;
%info;

 

arunrami
Pyrite | Level 9

Hi Brem, You are right. I was incorrectly using data step with dataline statment , thats what the cause of an error. Now working fine.

 

Thanks!! 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1679 views
  • 3 likes
  • 4 in conversation