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

Hi SAS communities, 

 

I need to summarize blood pressure by race, and I need my data to look like this (font, size doesn't matter):

sasquestion1.3.png

This is my current code: 

PROC SORT
DATA = Hypanl.noformatshyp2
OUT = WORK.noformatshyp2;
TITLE "Blood Pressure Summaries by Race";
BY RaceCd;
run;

PROC REPORT DATA = Hypanl.noformatshyp2 SPLIT = '/';
COLUMN RaceCd N (SBP DBP),(MEAN STD)
("Average Pressures"
("Systolic" SBP)
("Diastolic" DBP));
DEFINE RaceCd / GROUP 'Race Code';
DEFINE SBP / ANALYSIS MEAN FORMAT = 5.1 STD FORMAT = 4.1 'Systolic';
DEFINE DBP / FORMAT= 4.1 'Diastolic' ;
RBREAK AFTER / SUMMARIZE;
RUN;

 

Here is a picture of the code:

sasquestion1.2.png

And this is the result I am getting. I am not sure why I have another section of "Average Pressures" with blood pressure data underneath. I am thinking I nested the headers incorrectly, but I am not sure. 

sasquestion1.png

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
abrice520
Obsidian | Level 7

 

COLUMN RaceCd N
("Average Pressures" (SBP DBP),(MEAN STD));
DEFINE SBP / FORMAT= 5.1 "Systolic";
DEFINE DBP / "Diastolic";

I would suggest naming Systolic and Diastolic in the DEFINE statements so you don't have too many things in the COLUMN statement. I nested my headers a little bit differently from the other user who responded and it ends up being the same. The headings should be listed with the heading that includes the most variables first, and so on. So the "Average Pressures" should be listed before the variables that it will be heading, then SBP and DBP are listed, then the values underneath those. I also used a FORMAT for RaceCd. 

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @mdakkak and welcome to the SAS Support Communities!

 


@mdakkak wrote:

I am not sure why I have another section of "Average Pressures" with blood pressure data underneath.


This is because of the second mention of SBP and DBP in the COLUMN statement. Note that you also duplicate the headers "Systolic" and "Diastolic" by specifying them both in the COLUMN and in the DEFINE statements. Just insert the spanning header into the existing pair of parentheses around "SBP DBP."

 

Also, the second FORMAT= specification in the DEFINE statement for SBP overrides the first (and even that of the DEFINE statement for DBP). If you really needed to format means and standard deviations separately, you would use DEFINE statements for the statistics (and for aliases of the statistics if all four were to be formatted separately).

 

Usually a category like "Other Race" is sorted last. Depending on the internal values of RaceCd, the specification ORDER=internal can achieve this, but your PROC SORT step suggests that you actually wanted to use dataset WORK.noformatshyp2 in the PROC REPORT step and the option ORDER=data for variable RaceCd.

PROC REPORT DATA = WORK.noformatshyp2;
COLUMN RaceCd N ("Average Pressures" SBP DBP),(MEAN STD);
DEFINE RaceCd / GROUP 'Race Code' ORDER=data;
DEFINE SBP / FORMAT = 5.1 'Systolic';
DEFINE DBP / 'Diastolic';
RBREAK AFTER / SUMMARIZE;
RUN;
abrice520
Obsidian | Level 7

 

COLUMN RaceCd N
("Average Pressures" (SBP DBP),(MEAN STD));
DEFINE SBP / FORMAT= 5.1 "Systolic";
DEFINE DBP / "Diastolic";

I would suggest naming Systolic and Diastolic in the DEFINE statements so you don't have too many things in the COLUMN statement. I nested my headers a little bit differently from the other user who responded and it ends up being the same. The headings should be listed with the heading that includes the most variables first, and so on. So the "Average Pressures" should be listed before the variables that it will be heading, then SBP and DBP are listed, then the values underneath those. I also used a FORMAT for RaceCd. 

patrickjharvey
Calcite | Level 5

Hi,

 

Your column statement should be written as the following! You can rename SBP and DBP using the define statement. 

 

title "Blood Pressure Summaries by Race";
proc report data=hw;
column RaceCd N ("Average Pressures" SBP DBP ), (MEAN STD) ;
define RaceCd / group ;
define SBP / ANALYSIS MEAN STD format= 4.1 "Systolic";
define DBP / ANALYSIS MEAN STD format= 4.1 "Diastolic";
format RaceCd $RaceCdf.;
rbreak After/ Summarize;
run; 

 

 

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1814 views
  • 1 like
  • 4 in conversation