DATA Step, Macro, Functions and more

array question

Reply
N/A
Posts: 0

array question

Any idea what is wrong with this code?

array region{22} region_1 - region_22;
array ais{22} ais_1 - ais_22;
array trhead{22} trhead1-trhead22;
do i = 1 to dim(ais) ;
if region(i)='HEAD' then do trhead(i)=ais(i); end;
-
73
ERROR: The variable type of trhead is invalid in this context.
ERROR: Illegal reference to the array trhead.
ERROR 73-322: Expecting an =.

325 end;
Frequent Contributor
Posts: 139

Re: array question

My first guess would be that the array region is defined as numeric.

replace array region{22} region_1 - region_22;
array region{22} $ region_1 - region_22;

See what happens.

-Darryl
N/A
Posts: 0

Re: array question

Good idea, but it didn't help.


448 array region{22} $ region_1 - region_22;
449 array ais{22} ais_1 - ais_22;
450 array trhead{22} trhead1-trhead22;
451 do i = 1 to 22 ;
452 if region(i)='HEAD' then do trhead(i)=ais(i); end;
-
73
ERROR: The variable type of trhead is invalid in this context.
ERROR: Illegal reference to the array trhead.
ERROR 73-322: Expecting an =.

453 end;
Frequent Contributor
Posts: 139

Re: array question

I think I meant trhead but try to define them all as character

-Darryl
N/A
Posts: 0

Re: array question

The second ones should be numeric, but it still isn't working. Thanks for your help. I'm calling tech support.

513 array region{22} $ region_1 - region_22;
514 array ais{22} $ ais_1 - ais_22;
515 array trhead{22} $ trhead1-trhead22;
516 do i = 1 to 22 ;
517 if region(i)='HEAD' then do trhead(i)=ais(i); end;
-
73
ERROR: The variable type of trhead is invalid in this context.
ERROR: Illegal reference to the array trhead.
ERROR 73-322: Expecting an =.

518 end;
Frequent Contributor
Posts: 139

Re: array question

You need a semi-colon after the do

replace if region(i)='HEAD' then do trhead(i)=ais(i); end;
with
if region(i)='HEAD' then do; trhead(i)=ais(i); end;

-Darryl
Ask a Question
Discussion stats
  • 5 replies
  • 1382 views
  • 0 likes
  • 2 in conversation