BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
John4
Obsidian | Level 7

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 ?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

John4
Obsidian | Level 7

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 3 replies
  • 889 views
  • 3 likes
  • 2 in conversation