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?
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;
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.
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.));
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!
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.