BookmarkSubscribeRSS Feed
Nimish28
Calcite | Level 5

Hi 

 

I am trying to execute this Macro but the macro is hitting this error mentioned in the subject line . I have used this macro before as well and it worked fine .

Here is the macro code for reference 

%LET W = 1;
DATA
USER.DBDTL3_&PLN
;
SET
DBDTL2_&PLN
;
%IF %NUMOBS(DBDTL2_&PLN) > 0 %THEN %DO;
%DO %WHILE (&W <= &CDDCNT) ;
%IF &&CDD_FMT_&PLN._&W = 'A' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;

 

Kindly help .

6 REPLIES 6
Kurt_Bremser
Super User

You have two %do statements, but only one %end. This will lead to a compilation error when you define the macro, so it can't ever have worked. Unless you posted incomplete code, which makes it harder for us to help you.

 

Do the macro variables &CDD_FMT_xxx_yyy (xxx being the content of &PLN and yyy of &W) really contain the single quotes?

How does the function-style macro %NUMOBS create its result value? I guess that it results in a non-numeric value in certain conditions. To check this, we need to see the whole code of this macro.

Nimish28
Calcite | Level 5

Hi Kurt ,

Numobs macro just gives a count of number of observations .and the value of &PLAN is given as M1 and M2

and for &W is mentioned as below in the code .

Here is the full code
Note : Error message is coming out to be like 

ERROR: A character operand was found in the %EVAL function or %IF condition where

       &&CDD_FMT_&PLN._&W = A           

%LET W = 1;
DATA
USER.DBDTL3_&PLN
;
SET
DBDTL2_&PLN
;
%IF %NUMOBS(DBDTL2_&PLN) > 0 %THEN %DO;
%DO %WHILE (&W <= &CDDCNT) ;
%IF &&CDD_FMT_&PLN._&W = 'A' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'F' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'M' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'O' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'Q' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/100;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'P' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/1000;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'G' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/10000;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'J' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W,30.)/10000;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'H' %THEN %DO;
CDD_VL_&PLN._&W=INPUT(CDD_TX_&PLN._&W,30.)/1000000;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'OK' %THEN %DO;
CDD_VL_&PLN._&W=INPUT(CDD_TX_&PLN._&W,30.)/1000000;
%END;
%ELSE %IF &&CDD_FMT_&PLN._&W = 'D' %THEN %DO;
CDD_VL_&PLN._&W = INPUT(CDD_TX_&PLN._&W, YYMMDD10.);
FORMAT CDD_VL_&PLN._&W MMDDYY10.;
%END;
%ELSE %DO;
CDD_VL_&PLN._&W = CDD_TX_&PLN._&W ;
%END;

%LET W = %EVAL(&W + 1 );
%END; %* End of DO WHILE LOOP;
%END; %* End of NUMOBS > 0 if statement ;
RUN
;

Quentin
Super User

Agree, if you add:

 

%put >>&&CDD_FMT_&PLN._&W<<;

before the %IF statement what do you see?

There are many values that could trigger that error, for example: AND OR +-= 

 

gamotte
Rhodochrosite | Level 12

Hello,

 

I think you can achieve what you want in a more readable way and with less problems by not using macros

but plain SAS language.

 

Here is an example based on the code you've given, that you can adapt to your needs.

proc format;
    invalue denom
    'A', 'F', 'M', 'O', 'Q'=100
    'P'=1000
    'G', 'J'=10000
    'H', 'OK'=100000
    other=0;
run; 

%let PLN=PLN;
%let CDD_FMT_&PLN._1=G;
%let CDD_FMT_&PLN._2=A;

data want;
    length CDD_FMT $2.;

    CDD_TX_PLN_1="5000"; /* For the example */
    CDD_TX_PLN_2="200";
    format CDD_VL_PLN_1 CDD_VL_PLN_2 best.;

    array TX CDD_TX_PLN:;
    array VL CDD_VL:;

    do W=1 to 2;
        CDD_FMT=symget(cats("CDD_FMT_&PLN._",W));
        denom=input(CDD_FMT, denom.);
        CDD_TX=input(TX(W),30.);

        if denom then VL(W)=CDD_TX/denom;
        else if CDD_FMT='D' then VL(W)= input(TX(W), YYMMDD10.);
        else VL(W)=CDD_TX;
    end;
drop denom CDD_FMT; run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1514 views
  • 0 likes
  • 4 in conversation