BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KoVa
Obsidian | Level 7

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

KoVa
Obsidian | Level 7
thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 859 views
  • 1 like
  • 2 in conversation