BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;
Spoiler
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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User

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;
Spoiler
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;

 

Tom
Super User Tom
Super User

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;
ballardw
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 324 views
  • 1 like
  • 5 in conversation