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

I am not really sure what number is supposed to go into the array function.

These are the variables + the site_id I created. 

Variable

Description

subj_id

Subject ID

phy_id

physician ID

Fracture

1 = yes, 0 = no

momfrac

Mother had hip fracture

raterisk

self reported risk of fracture relative to others of the same age(same, less, greater,NA=missing)

priorfrac

history of prior fractures

age

subject age

height

height in cm at enrollment

weight

weight in kg at enrollment

 

 

libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7';
run; 
data glow_combined; 
set hw7.glow1 
hw7.glow2
hw7.glow3
hw7.glow4
hw7.glow5 
hw7.glow6; 
run;
data glow_combined; 
set hw7.glow1(in= glow1) 
hw7.glow2 (in=glow2)
hw7.glow3 (in=glow3) 
hw7.glow4 (in=glow4) 
hw7.glow5 (in=glow5)
hw7.glow6 (in=glow6); 
if glow1 then site_id  = 1;
if glow2 then site_id  = 2;
if glow3 then site_id = 3; 
if glow4 then site_id = 4;
if glow5 then site_id = 5;
if glow6 then site_id = 6;
run;
data glow_combined;
array miss[10] age weight weight;
do i = 1 to 10;
	if miss[i] = 999 then miss[i] = .;
end;
if miss[10] = 99 then miss[10] = .;
run;
This is the error code I received: 

148 libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7'; NOTE: Libref HW7 was successfully assigned as follows: Engine: V9 Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7 149 run; 150 data glow_combined; 151 set hw7.glow1 152 hw7.glow2 153 hw7.glow3 154 hw7.glow4 155 hw7.glow5 156 hw7.glow6; 157 run; NOTE: There were 107 observations read from the data set HW7.GLOW1. NOTE: There were 90 observations read from the data set HW7.GLOW2. NOTE: There were 65 observations read from the data set HW7.GLOW3. NOTE: There were 36 observations read from the data set HW7.GLOW4. NOTE: There were 120 observations read from the data set HW7.GLOW5. NOTE: There were 82 observations read from the data set HW7.GLOW6. NOTE: The data set WORK.GLOW_COMBINED has 500 observations and 9 variables. NOTE: DATA statement used (Total process time): real time 0.14 seconds cpu time 0.03 seconds 158 data glow_combined; 159 set hw7.glow1(in= glow1) 160 hw7.glow2 (in=glow2) 161 hw7.glow3 (in=glow3) 162 hw7.glow4 (in=glow4) 163 hw7.glow5 (in=glow5) 164 hw7.glow6 (in=glow6); 165 if glow1 then site_id = 1; 166 if glow2 then site_id = 2; 167 if glow3 then site_id = 3; 168 if glow4 then site_id = 4; 169 if glow5 then site_id = 5; 170 if glow6 then site_id = 6; 171 run; NOTE: There were 107 observations read from the data set HW7.GLOW1. NOTE: There were 90 observations read from the data set HW7.GLOW2. NOTE: There were 65 observations read from the data set HW7.GLOW3. NOTE: There were 36 observations read from the data set HW7.GLOW4. NOTE: There were 120 observations read from the data set HW7.GLOW5. NOTE: There were 82 observations read from the data set HW7.GLOW6. NOTE: The data set WORK.GLOW_COMBINED has 500 observations and 10 variables. NOTE: DATA statement used (Total process time): real time 0.12 seconds cpu time 0.00 seconds 172 data glow_combined; 173 array miss[10] age weight weight; ERROR: Too few variables defined for the dimension(s) specified for the array miss. 174 do i = 1 to 10; 175 if miss[i] = 999 then miss[i] = .; 176 end; 177 if miss[10] = 99 then miss[10] = .; 178 run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 175:8 177:4 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.GLOW_COMBINED may be incomplete. When this step was stopped there were 0 observations and 1 variables. WARNING: Data set WORK.GLOW_COMBINED was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.01 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
172  data glow_combined;
173  array miss[10] age weight weight;
ERROR: Too few variables defined for the dimension(s) specified for the array miss.

 

You defined an array with 10 elements, and then listed only 3. You probably want

 

data glow_combined;
array miss[3] age weight weight;
do i = 1 to 3;
   if miss[i] = 999 then miss[i] = .;
end;
run;

 

Please note that you have entered the variable WEIGHT twice into the array. I doubt that is what you want, it doesn't even make sense in an array; and I don't even know if that will work.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
172  data glow_combined;
173  array miss[10] age weight weight;
ERROR: Too few variables defined for the dimension(s) specified for the array miss.

 

You defined an array with 10 elements, and then listed only 3. You probably want

 

data glow_combined;
array miss[3] age weight weight;
do i = 1 to 3;
   if miss[i] = 999 then miss[i] = .;
end;
run;

 

Please note that you have entered the variable WEIGHT twice into the array. I doubt that is what you want, it doesn't even make sense in an array; and I don't even know if that will work.

--
Paige Miller
ballardw
Super User

AND missed a SET statement to bring any existing data to work with.

Reeza
Super User
libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7';

*This is not needed;
run; 


data glow_combined; 
set hw7.glow1 
hw7.glow2
hw7.glow3
hw7.glow4
hw7.glow5 
hw7.glow6; 
run;

*this data set is the same names as the data set created in the previous data step and will overwrite it;
data glow_combined; 
set hw7.glow1(in= glow1) 
hw7.glow2 (in=glow2)
hw7.glow3 (in=glow3) 
hw7.glow4 (in=glow4) 
hw7.glow5 (in=glow5)
hw7.glow6 (in=glow6); 

*this should be IF/ELSE IF not a series of IF;
if glow1 then site_id  = 1;
if glow2 then site_id  = 2;
if glow3 then site_id = 3; 
if glow4 then site_id = 4;
if glow5 then site_id = 5;
if glow6 then site_id = 6;
run;

*This will once again overwrite the data set created in the previous step;
data glow_combined;

*there is no input data set specified (no set statement);

*there are 3 variables but a dimension set of 10. Need to list ten variables or change the dimension to 10;
*do not use the word miss as an array name as SAS has a function missing and this could get confusing;
array miss[10] age weight weight;

*change the loop to match the number of variables in the array;
do i = 1 to 10;
	if miss[i] = 999 then miss[i] = .;
end;

*works only the 10th variable in the list, which is non existent at the moment;
if miss[10] = 99 then miss[10] = .;
run;

Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

I commented your code with the issues highlighted in red. 

Tom
Super User Tom
Super User

There is no ARRAY() function.  There is an ARRAY statement.  

 

If you are talking about the dimension of the array you don't need to supply any value for that. SAS can COUNT.  You don't need anything there at all.  Use the DIM() function (that is an actual function) to find the number of variables that the array is referencing.

array miss age height weight;
do i = 1 to dim(miss);

So assuming that someone made the mistake of designing your data entry system so that missing values are recorded as actual numbers and the goal is to recode those values to missing then just do each variable by itself.  If you have more then 5 variables that all used the same valid number to represent missing then perhaps it is worth making an array.

 

But for this problem there is no need to use an array.

if age=999 then age=.;
if height=99 then height=.;
if weight=999 then weight=.;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 681 views
  • 1 like
  • 5 in conversation