BookmarkSubscribeRSS Feed
savannah
Calcite | Level 5
How can I initalize the variable in the last steps? I do not get any observations as it shows an error..variables not initialized.
 
data totalstudentsgrd7togrd12;
 set impute_mid_schools impute_high_schools;
 if Teacher_mid>0 and Teacher_high>0;
 retain set impute_mid_schools impute_high_schools 0;
retain PTRatio_rev 0;
 Total_Students_grd7togrd12=sum(of mid_Grd7-mid_Grd12)+sum(of hs_Grd7-hs_Grd12);
 PTRatio_rev=Total_Students_grd7togrd12/Teachers;
 format Revised PTRatio 9.2;
 run;
6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Please post your log? Also, please post an example of what your data looks like.

 

Makes it so much easier to help you

savannah
Calcite | Level 5

Reinhardt:

 

I was missing a then...if....then

 

and i got the following log:

 

 Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1528 at 74:29 2138 at 74:55 1679 at 74:56 2138 at 76:40
 There were 610 observations read from the data set WORK.IMPUTE_MID_SCHOOLS.
 There were 459 observations read from the data set WORK.IMPUTE_HIGH_SCHOOLS.
 There were 1069 observations read from the data set WORK.TOTALTEACHERS.
The data set WORK.TOTALSTUDENTSGRD7TOGRD12 has 2138 observations and 24 variables.
FreelanceReinh
Jade | Level 19

Without having sample data this is a bit like detective work.

 

The missing values mentioned in the log can be explained as follows:

  • The six variables mid_Grd7-mid_Grd12 are all missing for the 459 observations from dataset IMPUTE_HIGH_SCHOOLS. Most probably they are simply not contained in that dataset.
  • The six variables hs_Grd7-hs_Grd12 are all missing for the 610 observations from dataset IMPUTE_MID_SCHOOLS. Again, most probably they are not contained in that dataset.
  • Certainly, none of the above 12 variables is contained in dataset TOTALTEACHERS (which contains only School, County and Teachers) with its 1069 observations.

That's why you get (in "line 74" of the log):

  • 459+1069=1528 missing values for sum(of mid_Grd7-mid_Grd12)
  • 610+1069=1679 missing values for sum(of hs_Grd7-hs_Grd12)
  • 459+610+1069=2138 missing values, i.e. only missing values, for variable Total_Students_grd7togrd12.

This last fact in turn explains the 2138 missing values you obtain for variable PTRatio_rev in "line 76" (by dividing missing values by values of variable Teachers, many of which are most likely also missing, because only dataset TOTALTEACHERS can be reasonably expected to contain this variable according to your first data step).

 

So, merely concatenating the three datasets with the SET statement does not create a suitable basis for your calculations. Here is an instructive example of what happened in your program: Using the SET Statement When Data Sets Contain Different Variables.

 

If you need more help, please post a few lines of sample data (for each of the three datasets involved) in the form of a datastep (see instructions) and describe what you want as output.

pau13rown
Lapis Lazuli | Level 10

"uninitialised" can be something as simple as a typo, for example you refer to variable "PTRatio" in a format statement but it is not defined anywhere, that would surely lead to "PTRatio is uninitialised" comment in the log. But you should specify which variable the log indicates is the problem

FreelanceReinh
Jade | Level 19

@savannah wrote:
I do not get any observations ...
 
data totalstudentsgrd7togrd12;
 set impute_mid_schools impute_high_schools;
 if Teacher_mid>0 and Teacher_high>0;
 

Please note that the above subsetting IF statement will indeed block out all observations if Teacher_mid is a variable in impute_mid_schools (but not in impute_high_schools) and Teacher_high is a variable in impute_high_schools (but not in impute_mid_schools).

 


@savannah wrote:
... variables not initialized.
 

The number of uninitialized variables will decrease as soon as you delete the line where you seem to combine a RETAIN and a SET statement (but in fact create an uninitialized variable named SET among others) and correct the FORMAT statement to

format PTRatio_rev 9.2;

("Revised PTRatio" is probably the label of variable PTRatio_rev.)

savannah
Calcite | Level 5

Reinhardt:

 

I have included the code and the log. I modified as per your suggestion but it does not give me any obs as seen in the log. SInce i am dividing in the last step I wanted data without any zeros or miss val. all the 3 data sets have the values.

 

 

 

data totalteachers (keep = School County Teachers);
set impute_mid_schools impute_high_schools;
Total_Teachers=sum(of Teacher_mid Teacher_high);
Teachers =ceil(Total_Teachers);
run;

data totalstudentsgrd7togrd12;
set impute_mid_schools impute_high_schools totalteachers;
if Teacher_mid>0 and Teacher_high>0;
Total_Students_grd7togrd12=sum(of mid_Grd7-mid_Grd12)+sum(of hs_Grd7-hs_Grd12);
retain PTRatio_rev 0;
PTRatio_rev=Total_Students_grd7togrd12/Teachers;
format PTRatio_rev 9.2;
run;

 

 

log

NOTE: There were 610 observations read from the data set WORK.IMPUTE_MID_SCHOOLS.
NOTE: There were 459 observations read from the data set WORK.IMPUTE_HIGH_SCHOOLS.
NOTE: There were 1069 observations read from the data set WORK.TOTALTEACHERS.
NOTE: The data set WORK.TOTALSTUDENTSGRD7TOGRD12 has 0 observations and 24 variables.
NOTE: DATA statement used (Total process time):

 

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!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1235 views
  • 0 likes
  • 4 in conversation