BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

I want to create one macro variable called 'entity_id' based on value of other macro variable 'legal_entity_cd'.

 

If value of 'legal_entity_cd' resolves to 'EXXP' then I want one macro variable called 'entity_id' and it should resolves to '12345'

If value of 'legal_entity_cd' resolves to 'EXPP' then I want one macro variable called 'entity_id' and it should resolves to '23456'

If value of 'legal_entity_cd' resolves to 'EEPP' then I want one macro variable called 'entity_id' and it should resolves to '34567'

 

How can I tackle this?

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please check the below code where we create the macro variables

 

%let EXXP= 12345;
%let legal_entity_cd=&exxp;
%let entity_id=&legal_entity_cd;

%put &entity_id;
Thanks,
Jag
ballardw
Super User

There can be a number of nuances depending on where you are placing this code but basically:

%If &legal_entity_cd = EXXP %then %let entity_id =12345;
%If &legal_entity_cd = EXPP %then %let entity_id =23456;
%If &legal_entity_cd = EXXP %then %let entity_id =34567;

Should work.

Note I have to assume you did not intend to place quotes int he NAME of the variable as that is not syntactically correct. And placing quotes as part of variables is one of the ways to make macro variables hard to use consistently.

s_lassen
Meteorite | Level 14

I would use an informat for that, seems most natural:

proc format;
  invalue ent_val
    'EXXP'=12345
    'EXPP'=23456
    'EEPP'=34567
    other=.
  ;
run;

%let entity_id=%sysfunc(input(&legal_entity_cd,ent_val.));

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
  • 3 replies
  • 811 views
  • 1 like
  • 4 in conversation