Jacques
Jacques

Reputation: 3

drop the character comma in a SAS macro string

I would like to drop the comma in the following list assigned to a macro variable : pop_freq_variabelen = nationaliteit_belg, urbanisatie_code, leeftijd1_code, ve_geslacht

I have used the following SAS command : %let varlist_ = %sysfunc(compress(&pop_freq_variabelen,','));

I got the following message : ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments. ERROR: The macro CREEER_MACRO_VARIABLEN will stop executing.

How can I solve this ?

Thanks in advance.

Upvotes: 0

Views: 760

Answers (2)

Tom
Tom

Reputation: 51566

When the macro expands there are commas in your function call. You need to protect the commas so %SYSFUNC() does not see them as argument separators. You are also including single quotes in the list of characters you are asking the COMPRESS() function to remove. So why not quote the first argument to protect any commas it might have. You will need to use double quote characters so the macro variable reference will be resolved. Adding double quotes into the list of characters to remove will both protect that comma and remove the quotes added to the first argument.

%let varlist_ = %sysfunc(compress("&pop_freq_variabelen",","));

Upvotes: 1

PeterClemmensen
PeterClemmensen

Reputation: 4937

Welcome :-)

The problem here is that the macro variable &pop_freq_variabelen resolves first. Since it contains a few commas, the Compress Function will give an error because it sees those commas as argument delimiters.

You can get around this with proper macro quoting functions.

%let pop_freq_variabelen = nationaliteit_belg, urbanisatie_code, leeftijd1_code, ve_geslacht;
%let varlist_ = %sysfunc(compress(%bquote(&pop_freq_variabelen.),%str(,)));

%put &varlist_.;

Upvotes: 1

Related Questions