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

Using SAS 9.4

 

I am running the greedy macro from the Mayo clinic college of medicine. 

 

%INCLUDE 'my location';
%gmatch(data=stacked,group= ca_co,id= obs4,
mvars= sex age_scope,wts=1 1,dmaxk=0 1,
ncontls= 1,seedca= 69,seedco= 14012,
out= stacked_greedy, outnmca= unmatch_casesa, outnmco= unmatch_controlsa );

 

when I run the above code it produces the following error

WARNING: Apparent symbolic reference NCO not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCA*1
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCO < %EVAL(&NCA*&NCONTLS)
ERROR: The macro GREEDY will stop executing.

 

Has anyone encountered this error or does anyone know what this error is referring to? Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Thanks, that helps. 

 

Look at this part of the log:

MPRINT(GREEDY): data __CHECK;
MPRINT(GREEDY): set stacked;
MPRINT(GREEDY): __id=obs4;
MPRINT(GREEDY): if __id="" then delete;
MPRINT(GREEDY): IF sex_greedy=. THEN DELETE;
MPRINT(GREEDY): IF age_scope=. THEN DELETE;
MPRINT(GREEDY): run;

NOTE: There were 14081 observations read from the data set WORK.STACKED.
NOTE: The data set WORK.__CHECK has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

It delete records with missing values for the following variables in your input dataset: OBS4 SEX_GREEDY AGE_SCOPE.

 

And it is deleting every record, and outputting a 0 observation data set, as I had suspected.

 

If you look at your source data and run:

proc freq data=stacked;
  tables obs4*sex_greedy*age_scope/missing list;
run; 

I assume it shows that every record has at least one missing value value for one of those variables?  

 

That would mean every record is being deleted, and there is no data to analyze.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

6 REPLIES 6
ballardw
Super User

@GS2 wrote:

Using SAS 9.4

 

I am running the greedy macro from the Mayo clinic college of medicine. 

 

%INCLUDE 'my location';
%gmatch(data=stacked,group= ca_co,id= obs4,
mvars= sex age_scope,wts=1 1,dmaxk=0 1,
ncontls= 1,seedca= 69,seedco= 14012,
out= stacked_greedy, outnmca= unmatch_casesa, outnmco= unmatch_controlsa );

 

when I run the above code it produces the following error

WARNING: Apparent symbolic reference NCO not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCA*1
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCO < %EVAL(&NCA*&NCONTLS)
ERROR: The macro GREEDY will stop executing.

 

Has anyone encountered this error or does anyone know what this error is referring to? Thank you


The "WARNING: Apparent symbolic reference NCO not resolved." type warnings typically mean that no value was supplied for a macro variable. That means there is no actual text to result for the %eval  which would be the result of attempting to compute something like a comparison.

In effect you have

 

<blank text> < (<blank value> * 1)

the evaluation doesn't have an actual value so fails because %eval does not know how to multiple a blank value times 1 and throws the error. The missing result on both sides of the comparison < won't help either.

 

When working with macros you often need to set

Options MPRINT;

to get more debug information. You may also need the SYMBOLGEN and MLOGIC options set. The log will show much more detail about the code generated by the macro and the errors will appear in relation to the generated code.

 

Actual cause could vary from expected macro variable not provided as parameters or the values passed to not generate valid values for the not resolved variables. Check to make sure you provided all the parameters the macro call expects. You may have to actually read the code for the macro to get that information.

Quentin
Super User

I would suggest you turn on MPRINT, and review the log.  In addition, review the macro code.

 

From a quick look at the macro code, it looks like it expects the variable you pass in the GROUP parameter to be coded 1/0 for case/control.  

 

You pass group=ca_co.

 

If your variable ca_co is not coded 0/1, the macro will not generate the macro variables NCA and NCO.

 

In this part of the macro code:

      DATA __CASE; SET _caco;
           if &group=1;
      DATA __CASE; SET __CASE END=EOF;
       KEEP __IDCA __CA1-__CA&NVAR __R &mvars
         %if &time^= %then %do;
             __catime
         %end;
          ;
         __IDCA=&ID;
         %if &time^= %then %do;
            __catime=&time;
         %end;
         %DO I=1 %TO &NVAR;
            __CA&I=&&V&I;
         %END;
         %if &seedca^= %then %do;
         SEED=&SEEDCA;
         __R=RANUNI( SEED  );
         %end;
         %else %do;
         __R=1;
         %end;
 
         IF EOF THEN CALL SYMPUT('NCA',_N_);

The data set __CASE will end up with 0 variables, so the CALL SYMPUT that creates the macro variable NCA will never execute.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

The variable ca_co is coded as a binary 1/0 in my data set. 

Quentin
Super User

I suggest you turn on options MPRINT, call the macro, and post the full log.  It should show (or at least give good clues) as to what is happening.  Assuming there are no errors or warnings before that point in the log, I would look for notes about datasets with 0 observations.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Below is the log as suggested after I turned on  mprints. Thank you

 

 

126 options mprint;
127 %INCLUDE 'G:\Outcomes Research\SAS Code\Completed Macros\GreedyMacro.sas';
780 %gmatch(data=stacked,group= ca_co, id= obs4,
781 mvars= sex_greedy age_scope,wts=1 1,dmaxk=0 1,
782 ncontls= 1,seedca= 69,seedco= 14012,
783 out= stacked_greedy, outnmca= unmatch_casesa, outnmco= unmatch_controlsa print=
783 ! y);
MPRINT(GMATCH): DATA _NULL_;
MPRINT(GMATCH): IF 1<0 THEN DO;
MPRINT(GMATCH): PUT 'ERROR: WEIGHTS MUST BE NON-NEGATIVE';
MPRINT(GMATCH): CALL SYMPUT('BAD','1');
MPRINT(GMATCH): END;
MPRINT(GMATCH): IF 1<0 THEN DO;
MPRINT(GMATCH): PUT 'ERROR: WEIGHTS MUST BE NON-NEGATIVE';
MPRINT(GMATCH): CALL SYMPUT('BAD','1');
MPRINT(GMATCH): END;
MPRINT(GMATCH): RUN;

NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


MPRINT(GMATCH): DATA _NULL_;
MPRINT(GMATCH): IF 0<0 THEN DO;
MPRINT(GMATCH): PUT 'ERROR: DMAXK VALUES MUST BE NON-NEGATIVE';
MPRINT(GMATCH): CALL SYMPUT('BAD','1');
MPRINT(GMATCH): END;
MPRINT(GMATCH): IF 1<0 THEN DO;
MPRINT(GMATCH): PUT 'ERROR: DMAXK VALUES MUST BE NON-NEGATIVE';
MPRINT(GMATCH): CALL SYMPUT('BAD','1');
MPRINT(GMATCH): END;
MPRINT(GMATCH): RUN;

NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


MPRINT(GREEDY): data __CHECK;
MPRINT(GREEDY): set stacked;
MPRINT(GREEDY): __id=obs4;
MPRINT(GREEDY): if __id="" then delete;
MPRINT(GREEDY): IF sex_greedy=. THEN DELETE;
MPRINT(GREEDY): IF age_scope=. THEN DELETE;
MPRINT(GREEDY): run;

NOTE: There were 14081 observations read from the data set WORK.STACKED.
NOTE: The data set WORK.__CHECK has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


MPRINT(GREEDY): *** transform data if requested/separate cases & controls;
MPRINT(GREEDY): data _caco;
MPRINT(GREEDY): set __check;

NOTE: There were 0 observations read from the data set WORK.__CHECK.
NOTE: The data set WORK._CACO has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


MPRINT(GREEDY): DATA __CASE;
MPRINT(GREEDY): SET _caco;
MPRINT(GREEDY): if ca_co=1;

NOTE: There were 0 observations read from the data set WORK._CACO.
NOTE: The data set WORK.__CASE has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


MPRINT(GREEDY): DATA __CASE;
MPRINT(GREEDY): SET __CASE END=EOF;
MPRINT(GREEDY): KEEP __IDCA __CA1-__CA2 __R sex_greedy age_scope ;
MPRINT(GREEDY): __IDCA=obs4;
MPRINT(GREEDY): __CA1=sex_greedy;
MPRINT(GREEDY): __CA2=age_scope;
MPRINT(GREEDY): SEED=69;
MPRINT(GREEDY): __R=RANUNI( SEED );
MPRINT(GREEDY): IF EOF THEN CALL SYMPUT('NCA',_N_);

NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
22:43
NOTE: There were 0 observations read from the data set WORK.__CASE.
NOTE: The data set WORK.__CASE has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


MPRINT(GREEDY): PROC SORT;
MPRINT(GREEDY): BY __R __IDCA;

NOTE: Input data set is empty.
NOTE: The data set WORK.__CASE has 0 observations and 6 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


MPRINT(GREEDY): DATA __CONT;
MPRINT(GREEDY): SET _caco;
MPRINT(GREEDY): if ca_co=0;

NOTE: There were 0 observations read from the data set WORK._CACO.
NOTE: The data set WORK.__CONT has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


MPRINT(GREEDY): DATA __CONT;
MPRINT(GREEDY): SET __CONT END=EOF;
MPRINT(GREEDY): KEEP __IDCO __CO1-__CO2 __R sex_greedy age_scope ;
MPRINT(GREEDY): __IDCO=obs4;
MPRINT(GREEDY): __CO1=sex_greedy;
MPRINT(GREEDY): __CO2=age_scope;
MPRINT(GREEDY): SEED=14012;
MPRINT(GREEDY): __R=RANUNI( SEED );
MPRINT(GREEDY): IF EOF THEN CALL SYMPUT('NCO',_N_);
MPRINT(GREEDY): RUN;

NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
33:43
NOTE: There were 0 observations read from the data set WORK.__CONT.
NOTE: The data set WORK.__CONT has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


WARNING: Apparent symbolic reference NCO not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
WARNING: Apparent symbolic reference NCA not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCA*1
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &NCO < %EVAL(&NCA*&NCONTLS)
ERROR: The macro GREEDY will stop executing.

 

Quentin
Super User

Thanks, that helps. 

 

Look at this part of the log:

MPRINT(GREEDY): data __CHECK;
MPRINT(GREEDY): set stacked;
MPRINT(GREEDY): __id=obs4;
MPRINT(GREEDY): if __id="" then delete;
MPRINT(GREEDY): IF sex_greedy=. THEN DELETE;
MPRINT(GREEDY): IF age_scope=. THEN DELETE;
MPRINT(GREEDY): run;

NOTE: There were 14081 observations read from the data set WORK.STACKED.
NOTE: The data set WORK.__CHECK has 0 observations and 39 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

It delete records with missing values for the following variables in your input dataset: OBS4 SEX_GREEDY AGE_SCOPE.

 

And it is deleting every record, and outputting a 0 observation data set, as I had suspected.

 

If you look at your source data and run:

proc freq data=stacked;
  tables obs4*sex_greedy*age_scope/missing list;
run; 

I assume it shows that every record has at least one missing value value for one of those variables?  

 

That would mean every record is being deleted, and there is no data to analyze.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1402 views
  • 0 likes
  • 3 in conversation