BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
5 REPLIES 5
darrylovia
Quartz | Level 8
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
deleted_user
Not applicable
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;
darrylovia
Quartz | Level 8
I think I meant trhead but try to define them all as character

-Darryl
deleted_user
Not applicable
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;
darrylovia
Quartz | Level 8
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2998 views
  • 0 likes
  • 2 in conversation