Hello,
I have error messages shown in the log window when I try to do an array. Please help; thanks.
data ds2;
set ds1;
array Var_Num{i} hcsfpcrothresult rapidrsvothersp ;
array Var_Cha{i} hcsfpcroth_result rapidrsvother_sp ;
do i = 1 to dim(Var_Cha);
Var_Num{i}=put(Var_Cha{i}, 3.);
drop Var_Num{i};
end;
run;
1883 array Var_Num{i} hcsfpcrothresult rapidrsvothersp ; - 22 202 ERROR: Too many variables defined for the dimension(s) specified for the array Var_Num. 1884 array Var_Cha{i} hcsfpcroth_result rapidrsvother_sp ; - 22 202 ERROR: Too many variables defined for the dimension(s) specified for the array Var_Cha. ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *. ERROR 202-322: The option or parameter is not recognized and will be ignored. 1885 do i = 1 to dim(Var_Cha); 1886 Var_Num{i}=put(Var_Cha{i}, 3.); 1887 drop Var_Num{i}; - 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 76-322: Syntax error, statement will be ignored. 1888 end;
You are not defining the array properly. You don't have to tell SAS how many variables are in the array when you have listed the variables explicitly. SAS can count.
array Var_Num hcsfpcrothresult rapidrsvothersp ;
array Var_Cha hcsfpcroth_result rapidrsvother_sp ;
If you want you can waste your time and specify the dimension then use either the actual dimension or a *.
array Var_Num [*] hcsfpcrothresult rapidrsvothersp ;
array Var_Cha [2] hcsfpcroth_result rapidrsvother_sp ;
You cannot drop an array. Only the actual variables.
drop hcsfpcrothresult rapidrsvothersp ;
Note: If you want to list a variable in the dimension of the array definition then you have to use regular parentheses instead of either square or curly brackets. But then you are defining an array that must index implicitly instead of explicitly since the variable name you put is the name of the variable that will be used to index the array
data ds2;
set ds1;
array Var_Num (i) hcsfpcrothresult rapidrsvothersp ;
array Var_Cha (i) hcsfpcroth_result rapidrsvother_sp ;
do i = 1 to dim(Var_Cha);
Var_Num=put(Var_Cha, 3.);
end;
drop hcsfpcrothresult rapidrsvothersp ;
run;
I think it is good advice for you to show us the ENTIRE log for this DATA step, not the portion you did show us.
In ARRAY statements, you put the number of elements inside the curly brackets, not a variable name like you did.
The log tells you the array declarations are wrong.
data ds2;
set ds1;
array Var_Num(2) hcsfpcrothresult rapidrsvothersp ;
array Var_Cha{2) hcsfpcroth_result rapidrsvother_sp ;
do i = 1 to dim(Var_Cha);
Var_Num{i}=put(Var_Cha{i}, 3.);
end;
drop hcsfpcrothresult rapidrsvothersp ;
run;
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
@ybz12003 wrote:
Hello,
I have error messages shown in the log window when I try to do an array. Please help; thanks.
data ds2; set ds1; array Var_Num{i} hcsfpcrothresult rapidrsvothersp ; array Var_Cha{i} hcsfpcroth_result rapidrsvother_sp ; do i = 1 to dim(Var_Cha); Var_Num{i}=put(Var_Cha{i}, 3.); drop Var_Num{i}; end; run;
Spoiler1883 array Var_Num{i} hcsfpcrothresult rapidrsvothersp ; - 22 202 ERROR: Too many variables defined for the dimension(s) specified for the array Var_Num. 1884 array Var_Cha{i} hcsfpcroth_result rapidrsvother_sp ; - 22 202 ERROR: Too many variables defined for the dimension(s) specified for the array Var_Cha. ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *. ERROR 202-322: The option or parameter is not recognized and will be ignored. 1885 do i = 1 to dim(Var_Cha); 1886 Var_Num{i}=put(Var_Cha{i}, 3.); 1887 drop Var_Num{i}; - 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 76-322: Syntax error, statement will be ignored. 1888 end;
You are not defining the array properly. You don't have to tell SAS how many variables are in the array when you have listed the variables explicitly. SAS can count.
array Var_Num hcsfpcrothresult rapidrsvothersp ;
array Var_Cha hcsfpcroth_result rapidrsvother_sp ;
If you want you can waste your time and specify the dimension then use either the actual dimension or a *.
array Var_Num [*] hcsfpcrothresult rapidrsvothersp ;
array Var_Cha [2] hcsfpcroth_result rapidrsvother_sp ;
You cannot drop an array. Only the actual variables.
drop hcsfpcrothresult rapidrsvothersp ;
Note: If you want to list a variable in the dimension of the array definition then you have to use regular parentheses instead of either square or curly brackets. But then you are defining an array that must index implicitly instead of explicitly since the variable name you put is the name of the variable that will be used to index the array
data ds2;
set ds1;
array Var_Num (i) hcsfpcrothresult rapidrsvothersp ;
array Var_Cha (i) hcsfpcroth_result rapidrsvother_sp ;
do i = 1 to dim(Var_Cha);
Var_Num=put(Var_Cha, 3.);
end;
drop hcsfpcrothresult rapidrsvothersp ;
run;
Create a value and then attempt to drop it?
Put a value, which creates character values, into what appears is intended to be numeric value?
Maybe describe what you intended to do, i.e. provide example values and the output.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.