DATA Step, Macro, Functions and more

Warning with PROC MEANS

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Warning with PROC MEANS

[ Edited ]

This is mydata :

data mydata;
input age note;
cards;
15  17.5
35  18
22  16.25
21  14.5
17  18.5
15 16
22 14.5
35 12.5
21 13.25
;
run;

and i want to compute note_Q1 and note_Q3 for each age. So I did :

%macro compute(age);
	%do i=1 %to &age;
			proc means data=mydata(where=(age=&i.)) q1 q3;
			var note;
			class age;
			ods output summary=data_&i.;
			run;

	%end;
%mend;

%compute(35);

but i get this warning message :

NOTE: There were 0 observations read from the data set WORK.MYDATA.
      WHERE age=1;

WARNING: Output 'summary' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also, 
         verify that the appropriate procedure options are used to produce the requested output object.  For example, verify that 
         the NOPRINT option is not used.

How can I get only on table with proc means result by age ?

 


Accepted Solutions
Solution
‎04-07-2017 05:02 AM
Super User
Super User
Posts: 7,997

Re: Warning with PROC MEANS

Well, your by group in that instance will be age so (note not tested as have no test data);

proc sort data=have;
  by age;
run;

proc means data=have;
  by age;
  var note;
  output out=want q1=q1 q3=q3;
run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,997

Re: Warning with PROC MEANS

Hi,

 

Lets start from fresh here, what is it your trying to achieve - post some example output.  Its never a good idea to jump into macro programming when its not fully understood.  What your macro is doing is repeating that proc means code for every number between 1 and &age.  So in the example it does:

proc means data=mydata(where=(age=1)) q1 q3;

Which will return 0 observations

proc means data=mydata(where=(age=2)) q1 q3;

 Which will return 0 observations etc.

 

I really can't state this clearly enough, macro is not a) a simple tool, b) not to be used to replace base SAS programming.  Anything you want to do can be done in base SAS, so don't complicate your thinking by macro'ing it.  Post example requirements for further help.

Contributor
Posts: 36

Re: Warning with PROC MEANS

Thanks. But how can i compute Q1 and Q3 since I dont have 1 to 35 but 15 to 35 ? (and its not 15, 16, 17, ... 35) ? I mean compute for each occurrence of age

Solution
‎04-07-2017 05:02 AM
Super User
Super User
Posts: 7,997

Re: Warning with PROC MEANS

Well, your by group in that instance will be age so (note not tested as have no test data);

proc sort data=have;
  by age;
run;

proc means data=have;
  by age;
  var note;
  output out=want q1=q1 q3=q3;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 118 views
  • 3 likes
  • 2 in conversation