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 ?
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;
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.
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
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: