I did use your Code. If not, please share the hole code. Copy my last and correct it. If you want to help, please Thank you.
Don't want to discuss about programmingstyle, thanks.
@obvisou wrote:
This Code gives this ERROR: Invalid Macro-Variable is already used by chkvaluelist_Add. ERROR 180-322: Statement is not valid or it is used out of proper order:
%global parameter_macrovariable; %let parameter_macrovariable =; %MACRO ChkValueList_Add(p_list =, p_value =); %if %sysfunc(findw(&p_list., %p_value.,,s)) %then %do; &p_list.; %end; %else %do; &p_list. &p_value.; %end; %MEND; ChkValueList_Add(p_list = ¶meter_macrovariable . ,p_value = Value1);
Remove the extra semicolons from these line:
...
&p_list.;
..
&p_list. &p_value.;
You do NOT want those to be part of the text that the macro emits.
Make sure to use the % when calling the macro. Without that CHKVALUELIST_ADD is ignored by the macro processor and so will cause a syntax error by SAS itself.
Finally call the macro in a place where a single string is expected by SAS.
Such as in an %LET macro statement.
%let parameter_macrovariable = %ChkValueList_Add(p_list = ¶meter_macrovariable . ,p_value = Value1);
So if you set
%let parameter_macrovariable = ABC ;
And then run :
%let parameter_macrovariable = %ChkValueList_Add(p_list = ¶meter_macrovariable . ,p_value = Value1);
You will get
ABC Value1
Assigned to parameter_macrovariable .
12:32 PM you posted this, with extra Semicolon on the end (%then ¤t;)
%macro check_and_add(current,new);
%if %sysfunc(findw(¤t,&new,,s)) %then ¤t;
%else ¤t &new;
%mend;
After your last post you mentioned without Semicolon and now it works! Thank you very much. I have to accept that the same Macro-Variable must be entered twice:
%let parameter_macrovariable = %ChkValueList_Add(p_list = ¶meter_macrovariable . ,p_value = Value1);
And about your comment why use %put-Statments. Please do not forget, we are using SAS, which is sometimes a pain. It makes a big difference if you write Code in a Macro, in Data Set, outside Macro etc... I prefer to write more Code, who is working almost everywhere.
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.