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

Please see the following code. 

 

%LET NOMOUNTCYR1 = 'AL';

%LET NOMOUNTCYR1_unquoted=%qsysfunc(compress(&NOMOUNTCYR1,%str(%')));  

 

This successfully removes the single quotes from AL.

 

%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%qsysfunc(compress(&NOMOUNTCYR2,%str(%'))); 

 

This does not, I get the following error:

ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.

 

Each state abbreviation needs to be in quotes in the original macro variable so it can be used in a where statement later on. 

 

Please help me so that NOMOUNTCYR2_unquoted resolves to GA, MO, NM, OR

 

Thanks.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

 you missed to bquote 

 


%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%qsysfunc(compress(%bquote(&NOMOUNTCYR2),%str(%')));
%put &NOMOUNTCYR2_unquoted;

View solution in original post

7 REPLIES 7
Reeza
Super User

Probably an easier way than this:

 

%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%sysfunc(dequote(%sysfunc(translate("&nomountcyr2", " ", "'"))));

%put &NOMOUNTCYR2_unquoted; 

I would say create two separate ones from the start if at all possible.

 

proc sql noprint;
select distinct quote(stateCode, "'"), stateCode 
    into 
        :list1 separated by ",", 
        :list2 separated by ","
from sashelp.zipcode;
quit;

%put List1: &list1.;
%put List2: &list2.;

 


@martyvd wrote:

Please see the following code. 

 

%LET NOMOUNTCYR1 = 'AL';

%LET NOMOUNTCYR1_unquoted=%qsysfunc(compress(&NOMOUNTCYR1,%str(%')));  

 

This successfully removes the single quotes from AL.

 

%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%qsysfunc(compress(&NOMOUNTCYR2,%str(%'))); 

 

This does not, I get the following error:

ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.

 

Each state abbreviation needs to be in quotes in the original macro variable so it can be used in a where statement later on. 

 

Please help me so that NOMOUNTCYR2_unquoted resolves to GA, MO, NM, OR

 

Thanks.

 

 

 

 

 



 

novinosrin
Tourmaline | Level 20

 you missed to bquote 

 


%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%qsysfunc(compress(%bquote(&NOMOUNTCYR2),%str(%')));
%put &NOMOUNTCYR2_unquoted;

novinosrin
Tourmaline | Level 20

or using %superq

 

%LET NOMOUNTCYR2 = 'GA','MO','NM','OR';

%LET NOMOUNTCYR2_unquoted=%qsysfunc(compress(%superq(NOMOUNTCYR2),%str(%')));
%put &NOMOUNTCYR2_unquoted;

ballardw
Super User

@martyvd wrote:

 

Each state abbreviation needs to be in quotes in the original macro variable so it can be used in a where statement later on. 

 


If your WHERE statement is something like :

Where state in (&NOMOUNTCYR2.) ;

 

Then you do not need the commas imbedded in the macro variable which are the cause of the too many parameters issue more than likely. The requirement to have commas delimiting items in the IN operator went away maybe in SAS 9.0?

martyvd
Fluorite | Level 6

True, but I failed to mention I also use &NOMOUNTCYR2_unquoted in a output table footnote where I would like the commas to remain. 

 

I specified needing the quotes which I believe are required in the where statement for character variables. 

Reeza
Super User

@martyvd There are a few solutions posted that seem correct. Please mark one as the solution if your problem is resolved or clarify if something is still not working. 

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
  • 7 replies
  • 7557 views
  • 4 likes
  • 5 in conversation