Debugging error:Required operator not found in expression

Reply
New Contributor
Posts: 3

Debugging error:Required operator not found in expression

am working on the study day macro below but it gives an error in the log the program is a reference code as am new to sas clinical  i was trying to calculate studyday by accepting 3 columns from 3 tables to be used to calculate the studyday... can u help me with this... requirement... thanks

 

SYMBOLGEN: Macro variable ENDC resolves to aestdtc

SYMBOLGEN: Macro variable ENDC resolves to aestdtc

ERROR: Required operator not found in expression: length(&endc)=10

ERROR: The macro STDYDATES will stop executing.

 

plz can anyone give a idea on how this statement can be resolved?

 

%macro stdydates(studyday=, endc=, refdate=);

%if &endc= '' %then &studyday=.;
 %else %do;
    %if length(&endc)=10 %then %do;
    %if input(substr(&endc,1,10),yymmdd10.) < input(substr(&refdate,1,10),yymmdd10.)
    %then &studyday=input(substr(&endc,1,10), yymmdd10.) -
    input(substr(&refdate,1,10), yymmdd10.);
    %else &studyday=input(substr(&endc,1,10), yymmdd10.) -
    input(substr(&refdate,1,10), yymmdd10.) + 1;
 %end;
 %else %if length(&endc)=8 %then %do;
    %if input(&endc, yymmdd8.)<input(substr(&refdate,1,10), yymmdd10.)
    %then &studyday=input(&endc, yymmdd8.) - input(substr(&refdate,1,10),yymmdd10.);
    %else &studyday=input(&endc, yymmdd8.) - input(substr(&refdate,1,10), yymmdd10.)+1;
 %end;
 %end;
%mend stdydates;
options mprint symbolgen;
%stdydates(studyday=ST,endc=aestdtc, refdate=rfstdtc);

 

 

Esteemed Advisor
Posts: 6,661

Re: Debugging error:Required operator not found in expression

You suffer the typical misunderstanding of the macro language. The macro is a pre-processor for generating program text.

 

To manipulate data, use a data step.

 

So what is it that you want to achieve?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: Debugging error:Required operator not found in expression

[ Edited ]

Erm, where did you get the code?  This:

   %if length(&endc)=10 %then %do;

Will not work, you are writing macro logic %if %then... and using datastep functions - length() - which are incompatible.  Much the same as you will not be able to use input() in macro language like that.   What is it your trying to do, please post test data in the form of a datastep (just one or two lines will be sufficient), and what the output should look like.  From what you post below, you look like you are trying to replace some datastep code with macro code but you don't just replce datastep commands with macro ones.  Also I would say most of that code isn't needed, if you provide some test data I can elaborate.

 

Here I show some code that does what I think your after - note your SLDC documentation (you do write documentation for general programs yes?) will tell you most of the code anyways:

data have;
  length aestdtc rfstdtc $20;
  aestdtc="20140607"; rfstdtc="20140104"; output;
  aestdtc=""; rfstdtc="20140104"; output;
  aestdtc="2014-06-07"; rfstdtc="20140104"; output;
run;

%macro St (inds=,outds=,start=,ref=,result=);
  data &outds. (drop=start_num ref_num);
    set &inds.;
    start_num=input(compress(&start.,"-"),anydtdte.);
    ref_num=input(compress(&ref.,"-"),anydtdte.);
    if start_num ne . and ref_num ne . then &result.=start_num - ref_num;
    if start_num ne . and start_num < ref_num then &result.=&result. + 1;
  run;
%mend St;

%St (inds=have,outds=want,start=aestdtc,ref=rfstdtc,result=st);
Ask a Question
Discussion stats
  • 2 replies
  • 107 views
  • 0 likes
  • 3 in conversation