Hi guys,
I want to create a macro function that I can use in a data step.
it checks the value of variable1 (langa), which in the tables I use always is a char variable ('1','2').
if the value is = '2' then the outcome of the function should be a concatenation of 'OPTN_' and whatever value is in variable2(date_). if not, then it should be 'OPTF_'||var2.
here is what I have so far (I used do steps since I plan on adding some stuff there later)
*rsubmit;
%macro ts_date_nice(langa, date_);
%if &langa = '2' %then
%do;
%let dn = 'OPTN_'||&date_;
%end;
%else
%do;
%let dn = 'OPTF_'||&date_;
%end;
&dn;
%mend ts_date_nice;
i tried it like this on a test table:
BROLNG ACT_PRD
2 NLB
1 NLC
data check;
set testtbl;
daten = %ts_date_nice (BROLNG,ACT_PRD);
run;
result of the new variable daten is however
OPTF__NLB
OPTF__NLC
so the concatenation works, but there is something wrong with the if statement?
I have tried without the '' (so just %if &langa = 2) but that didn't change anything. also ran it on other tables, same result.
The macro processor is a code generator and does its work before the resulting code is handed off to the base SAS interpreter.
To do what you want, macro language is useless. What you want is a data step custom function created with PROC FCMP.
The macro processor is a code generator and does its work before the resulting code is handed off to the base SAS interpreter.
To do what you want, macro language is useless. What you want is a data step custom function created with PROC FCMP.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: