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.));
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.