BookmarkSubscribeRSS Feed
lloydc
Calcite | Level 5

I want to pass the contents of an entire     IN list. Each of the elements in the list have to be quoted. What I have is:

%LET INECCGRP = "('1-1' '1-3' '1-5' '1-7' '1-9' '1-11' '1-13' '1-15')";

As shown below, the macro variable INECCGRP resolves to:     "('1-1' '1-3' '1-5' '1-7' '1-9' '1-11' '1-13' '1-15')"

including the leading and trailing double-quotation marks which make that invalid at execution.

I'm sure this is some combination of the xQUOTE functions but I'm not hitting the right ones in playing trial and error.

The users of this program will edit the %LET statements but not the underlying macro.

Any help is appreciated.

Error received:

 

44021 /* ----------------------------------------------------------------------------------------- ------------------- */

44022 /* Below: list the Parity Groups to be used for the Pool's P-Vols. Use single quote

44022! marks with a hyphen */

44023 /* Example: if ECC_Group in ('1-1' '1-3' '1-5' '1'7');

44023! */

44024 /*

44024! -----------------------------------------------------------------------------------------

44024! ------------------- */

44025

44026 DQINECC1 = length((%STR(&INECCGRP)));

SYMBOLGEN: Macro variable INECCGRP resolves to "('1-1' '1-3' '1-5' '1-7' 1-9' '1-11' '1-13'

'1-15')"

44027 DQINECC2 = substr(&INECCGRP,2,(DQINECC1-1)); put @ 001 "DQINECC2=" DQINECC2;

SYMBOLGEN: Macro variable INECCGRP resolves to "('1-1' '1-3' '1-5' '1-7' 1-9' '1-11' '1-13'

'1-15')"

44028

44029 if ECC_Group in DQINECC2;

ERROR: The right-hand operand must be an array name or a constant value list. The specified

name DQINECC2, is not an array.

44030

44031

44032

44033 /*('1-1' '1-2' '1-3' '1-4' '1-5' '1-6' '1-7' '1-8' '1-9' '1-10' '1-11' '1-12' '1-13'

44033! '1-14' '1-15') ; */

44034

4 REPLIES 4
Tom
Super User Tom
Super User

Your actual error message is from the miss use of the IN operator in the SAS and not from the macro variable.

You have written: if ECC_GROUP in DQINECC2

You cannot use the IN operator with a single character variable.  You need to use in in the form

if ECC_GROUP in ('1-1' '1-3' '1-5' '1-7' '1-9' '1-11' '1-13' '1-15') ...

You could use the macro variable but you would need to get rid of the unneeded extra double quote characters around the outside.

%LET INECCGRP = ('1-1' '1-3' '1-5' '1-7' '1-9' '1-11' '1-13' '1-15') ;

...

if ECC_Group in &ineccgrp ;

Why did you include the double quotes in the first place?

lloydc
Calcite | Level 5

It wouldn't accept the value including the parenthesis without the double quotes

ballardw
Super User

A programming style choice. I would tend not to disguise the purpose of the macro variable as a combination of parentheses and a value list.

%let INECCGRP = '1-1' '1-3' '1-5' '1-7' '1-9' '1-11' '1-13' '1-15';

and in the datastep

if ECC_group in (&ineccgrp);

then when I read the code much later I will realize the &inccgrp relates to a list of values. and that's all (hopefully).

Tom
Super User Tom
Super User

What wouldn't accept them?  The %LET statement doesn't care.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2762 views
  • 0 likes
  • 3 in conversation