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;
Die auf WeAreCAS.eu bereitgestellten Codes und Beispiele dienen Lehrzwecken. Es ist zwingend erforderlich, sie nicht blind in Ihre Produktionsumgebungen zu kopieren. Der beste Ansatz besteht darin, die Logik zu verstehen, bevor sie angewendet wird. Wir empfehlen dringend, diese Skripte in einer Testumgebung (Sandbox/Dev) zu testen. WeAreCAS übernimmt keine Verantwortung für mögliche Auswirkungen oder Datenverluste auf Ihren Systemen.
SAS und alle anderen Produkt- oder Dienstleistungsnamen von SAS Institute Inc. sind eingetragene Marken oder Marken von SAS Institute Inc. in den USA und anderen Ländern. ® zeigt die Registrierung in den USA an. WeAreCAS ist eine unabhängige Community-Site und nicht mit SAS Institute Inc. verbunden.
Diese Website verwendet technische und analytische Cookies, um Ihre Erfahrung zu verbessern.
Mehr erfahren.