DATA Step, Macro, Functions and more

error with macro

Reply
Occasional Contributor
Posts: 8

error with macro

Hi there,

 

I have got the following error message:

 

"557: LINE and COLUMN cannot be determined.

NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.

ERROR 557-185: Variable fisrt is not an object.

ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

user cpu time 0.00 seconds

system cpu time 0.00 seconds

memory 131.12k

OS Memory 14892.00k

Timestamp 01/14/2016 10:32:49 AM

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

5, 10

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro HP3067 will stop executing."

 

The macro is as belw:

 

%macro HP3067(yr1, yr2, yr3);

data HP;

set hosp_proc&yr2 hosp_proc&yr3;

%sort(HP, Indig);

data HP;

set HP;

by indig;

if fisrt.indig then do;

%do i=1 %to 5, 10;

p&i=0;

%end;

total=0;

end;

total+1;

%do i=1 %to 5, 10;

if procedure_no=&i then p&i+1;

%end;

%do i=1 %to 5, 10;

pct&i=p&i/total* 100;

%end;

pt=100;

if last.indig then output;

run;

%mend;

 

Anyone can tell me what I did wrong? Thanks.

 

qinghe

Occasional Contributor
Posts: 8

Re: error with macro

I just notice the wrong spelling of "fisrt". Sorry about that

Super User
Posts: 17,784

Re: error with macro

Does that fix your error?

 

I will mention that your code may be easier to understand and navigate via arrays rather than macro variables. I'm not sure they add value to your process, beyond the year definitions.

Occasional Contributor
Posts: 8

Re: error with macro

Hi Reeza

 

This is not the only error. The macro %to does not accept 5, 10. For 10 I have to do it seperately. You are right, use array should be easier. Thanks.

 

Qinghe

Super User
Super User
Posts: 7,392

Re: error with macro

Hi,

 

There are few things incorrect in there.  The typo in first as picked up before.  Also you do not retain total so that wont work.  I am not sure about a lot of the syntax you have used either.  I would suggest that you post example test data (in the form of a datastep) and required output.  Also note that good code formatting really helps others to read your code - indetation, consitent casing - finishing blocks - not creating obfuscation macros (%sort, what does it do, how do I use it etc. versus proc sort which I know how to use).  I have tried tidying up the code below, and show the use of arrays, but without data I can't really compress any.

 

 

data hp;
  set hosp_proc2012 hosp_proc2013;
run;

proc sort data=hp;
  by indig;
run;

data hp;
  set hp; 
  by indig;
  retain total;
  array p{3} 8.;
  array pct{3} 8.;
  array tests{3} 8. (1,5,10);
  if first.indig then do;
    call missing(of p{*});
    total=0;
  end;
  total=total+1;
  do i=1 to 3;
    if procedure_no=tests{i} then p{i}=p{i}+1;
  end;
  do i=1 to 3;
    pct{i}=(p{i} / total) * 100;
  end;
  if last.indig then output;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 290 views
  • 0 likes
  • 3 in conversation