BookmarkSubscribeRSS Feed
Banu
Obsidian | Level 7

HI Team,

 

I am customizing the code to run the job in all environments. Below is sample code existing today.

 

%macro DATA_CONN_DEV;

%PUT "It's a DEV ";

%mend DATA_CONN_DEV;

 

Now I have modified the code to customize.

%let reg=dev;

 

%macro DATA_CONN_&reg.; ---> Here macro name should contain environment name like dev,uat or prod

%PUT "It's a &reg,";

%mend DATA_CONN_&reg.;

%DATA_CONN_&reg.;

 

If I mention environment values in %let statement above code should work for all DEV,UAT,PROD.

But I am getting below error. Please suggest me what is the better way to customize this code.

 

ERROR: Expected semicolon not found. The macro will not be compiled.

ERROR: A dummy macro will be compiled.

2 REPLIES 2
Kurt_Bremser
Super User

Just use a macro parameter:

%macro data_conn_dev(reg);
%put "It's a &reg.";
%mend data_conn_dev;

%let reg=DEV;

%data_conn_dev(&reg.);

Note that &reg. is local within the macro, so it's safe to use the same name in the global macro context.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would not do it like that.  The line:

%macro DATA_CONN_&reg.; 

This is the macro signature, it needs to be fixed, you cannot macrotize macro!

 

What you want is a macro parameter:

%macro data_conn (env=);
  %put Its a &env.;
%mend data_conn;

%data_conn (env=dev);
%data_conn (env=prod);

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
  • 2 replies
  • 481 views
  • 0 likes
  • 3 in conversation