An instructive exchange on the user forum perfectly illustrates this scenario with the use of Arrays and DO blocks.
Note : The Guilty Code
A user attempts to copy values from one array (ais) to another (trhead) under a condition, inside a loop.
Here is the submitted 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) ;
/* La ligne problématique */
if region(i)='HEAD' then do trhead(i)=ais(i); end;
end;
ERROR: The variable type of trhead is invalid in this context.ERROR: Illegal reference to the array trhead.ERROR 73-322: Expecting an =.
At first glance, one might think that the trhead array is improperly declared or that there is a type mismatch (numeric vs. character).
Note : The Diagnosis: The THEN DO Trap
As quickly identified by the forum experts, the problem has nothing to do with the arrays. It's a classic punctuation error.
The DO statement is a standalone instruction. It must end with a semicolon.
The correction: You must add a semicolon right after the DO.
if region(i)='HEAD' then do; trhead(i)=ais(i); end;
1
IF region(i)='HEAD'THENDO;
2
trhead(i)=ais(i);
3
END;
4
Note : The Golden Rule (Rule #1)
A user named David recalls in the discussion a fundamental rule taught to beginners but often forgotten by experts in the heat of the moment:
Formatting Tip
To avoid this specific error, it's recommended not to write the THEN DO and the following statement on the same line. Adopt the following indentation to make the error visually obvious:
if region(i)='HEAD' then do; /* Le point-virgule est bien visible ici */
trhead(i) = ais(i);
end;
Los códigos y ejemplos proporcionados en WeAreCAS.eu son con fines educativos. Es imperativo no copiarlos y pegarlos ciegamente en sus entornos de producción. El mejor enfoque es comprender la lógica antes de aplicarla. Recomendamos encarecidamente probar estos scripts en un entorno de prueba (Sandbox/Dev). WeAreCAS no acepta ninguna responsabilidad por cualquier impacto o pérdida de datos en sus sistemas.
SAS y todos los demás nombres de productos o servicios de SAS Institute Inc. son marcas registradas o marcas comerciales de SAS Institute Inc. en los EE. UU. y otros países. ® indica registro en los EE. UU. WeAreCAS es un sitio comunitario independiente y no está afiliado a SAS Institute Inc.
Este sitio utiliza cookies técnicas y analíticas para mejorar su experiencia.
Saber más.