Help using Base SAS procedures

Proc Means

Reply
Occasional Contributor
Posts: 5

Proc Means

[ Edited ]

Hello, 

 

I am having trouble getting the last statement in my project to work. I am trying to look at the variable absences for all three schooltypes (elementary, middle, and high) but only for specific county. I have gotten it to the point where I used the by statement to see all four counties separately, but I only want the print out to have specific county. Would anyone have any insight on the correct statement to add to narrow down the categories? I attached the code I have created so far. 

 

Thank you

Super User
Super User
Posts: 9,599

Re: Proc Means

Posted in reply to cpowell13

You would use a where clause, e.g. 

where district="volusia";
Occasional Contributor
Posts: 5

Re: Proc Means

Thank you for your suggestion, but it looks like now there is output in the results viewer for that procedure when I add in the statement. Whenever I add the where statement (I tried that solution earlier) in the log says "No observations were selected from dataset Work.Project2a". As soon as I remove the where statement the code runs, but gives me all four of the districts. 

 

Any thoughts on another "fix"? 

Super User
Super User
Posts: 9,599

Re: Proc Means

Posted in reply to cpowell13

Then that tells you that the information you have put in the where clause does not match your data, for instance:

district="Volusia"

 

where district="volusia";

Will return zero observations as Volusia does not equal volusia.  Also note you may need to strip blanks out:

where strip(upcase(district))="VOLUSIA";

Its impossible for me to say exactly as I cannot see your data - post test data in the form of a datastep in future:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

Occasional Contributor
Posts: 5

Re: Proc Means

[ Edited ]

I apologize for the improper protocol. I thought attaching the code was the way to go! Here is my code: 

 

 

Super User
Super User
Posts: 9,599

Re: Proc Means

[ Edited ]
Posted in reply to cpowell13

So:

data project2;
  input absences1-absences6; 
  if 1 _n_ in (1,2,3,4,5,6) then District = 'Okeechobee';
  else if _n_ in (7,8,9,10,11,12) then District = 'Seminole';
  else if _n_ in (13,14,15,16,17,18) then District = 'Volusia';
  else District = 'Walton';
  if _n_ in (1,2,7,8,13,14,19,20) then Race= 'B';
  else if _n_ in (3,4,9,10,15,16,21,22) then race='W';
  else race = 'O';

  if _n_ in (1,3,5,7,9,11,13,15,17,19,21,23) then Gender = 'M';
  else Gender = 'F';
  
array p2[*] _numeric_;
do i=1 to dim(p2);
if i>3 then Learntype = 'active';
else learntype = 'passive';
if i in (1,4) then schooltype = 'elementary';
else if i in (2,5) then schooltype = 'middle';
else schooltype = 'high';
absences = p2[i];
output;
end;

drop i absences1-absences6;

datalines;
100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750
3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100
350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100
480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;

proc print data=project2;
  where district="Volusia";
run;
proc means data=project2 sum maxdec=0;
where district="Volusia";
class schooltype;
var Absences;
title 'Total absences for volusia district by schooltype';
run;
Occasional Contributor
Posts: 5

Re: Proc Means

[ Edited ]

I now have this after your suggestion: 

 

The log is still saying there are no observations for both the proc print and proc means statement...

Super User
Super User
Posts: 9,599

Re: Proc Means

Posted in reply to cpowell13

And you are still ignoring what I posted.

"Volusia" form here:

else if _n_ in (13,14,15,16,17,18) then District = 'Volusia';

 

is not the same as "volusia":

where district = 'volusia';

 

So you do not get any observations.  

 

Respected Advisor
Posts: 3,852

Re: Proc Means

Posted in reply to cpowell13

How about this for reading your data.

 

data comp;
   do District = 'Okeechobee', 'Seminole', 'Volusia', 'Walton';
      do race = 'B','W','O';
         do Gender = 'M','F';
            do Learntype = 'passive','active';
               do schooltype='elementary','middle','high';
                  input absences @;
                  output;
                  end;
               end;
            end;
         end;
      end;           
datalines;
100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750

3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100

350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100

480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;
Ask a Question
Discussion stats
  • 8 replies
  • 96 views
  • 0 likes
  • 3 in conversation