BookmarkSubscribeRSS Feed
Riaz97
Calcite | Level 5

Use SASHELP.HEART
Write a macro to do the following.
Find summary statistics N, Mean , Median, Std , Min, Max for Weight by categories in
Weight_status, and Diastolic BP by categories in BP_status
The n will be reported to 0 decimal and mean and median will be reported to 1 decimals. The standard
deviation (SD) will be reported to 2 decimal. The min and max will be reported to 0 decimal.
Display as below using Proc report to an .rtf file

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Why do you want a macro that does so?

ballardw
Super User

Since a standard report will do that what is the Macro actually supposed to accomplish? Typically a macro is used to be somewhat dynamic with something in the code changing in response to values of data or parameters. You do not mention any such need.

 

If you expect someone to do your homework, expect to get asked a lot of "what have you tried so far" questions.

Riaz97
Calcite | Level 5


data s;
set sashelp.heart;
run;
proc sort data=s;
by status;
run;

proc freq data=s;
table status/nocum out=x;
run;

proc sql;
select count into :n1 - :n2 from x
order by status;
run;
%put &n1,&n2;

proc means data=s N mean median std min max;
var weight;
class weight_status;
by Status;
output out=outp;
run;

data s2;
set outp(drop=_type_ _freq_);
if missing(status) or missing(weight_status) then delete;
run;

proc means data=s N mean median std min max;
var Diastolic;
class bp_Status;
by status;
output out=outp1;
run;

data s3;
set outp1(drop=_type_ _freq_);
if missing(status) or missing(bp_status) then delete;
run;

proc transpose data=s3 out=s4;
by status BP_Status ;
var Diastolic;
/*id abbre;*/
run;

proc transpose data=s4 out=s5;
by status _name_;
var COL1 col2 col3 col4 col5;
/*id abbre;*/
run;

 

proc report data=base3 headskip headline nowd center split='*';
column Category Summary_statistics ("Dead" ND ) ("Alive" NA );
define Category/ "Category" ;
define ND/ "East*(N=&n2)";
define NA/ "West*(N=&n1)";
run;

PaigeMiller
Diamond | Level 26

I point out that there's no macro involved here in your code, there are macro variables, which is a different thing that a macro. And its impossible to see how a macro would apply in this assignment, although it is possible to see how macro variables apply here as you have shown. If your professor is giving you an assignment and he doesn't distinguish between these two, then your professor needs to learn the proper terminology.

 

By the way, now that you have shown us actual code, what is wrong with the code?

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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