BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
obvisou
Fluorite | Level 6

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.

 

 

Tom
Super User Tom
Super User

@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 = &parameter_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 = &parameter_macrovariable .  ,p_value = Value1);

So if you set 

%let parameter_macrovariable = ABC ;

And then run :

%let parameter_macrovariable = %ChkValueList_Add(p_list = &parameter_macrovariable .  ,p_value = Value1);

You will get 

ABC Value1

Assigned to parameter_macrovariable .

obvisou
Fluorite | Level 6

12:32 PM you posted this, with extra Semicolon on the end (%then &current;)

%macro check_and_add(current,new);
%if %sysfunc(findw(&current,&new,,s)) %then &current;
%else &current &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 = &parameter_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.

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 32 replies
  • 2032 views
  • 1 like
  • 5 in conversation