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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2060 views
  • 1 like
  • 4 in conversation