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

Hi SAS experts,

Although I am using SAS for a while now, I am a newbie to PROC REPORT. I am trying to create a simple report using following data

GroupVALUEstateFrequencyColPercent
AYes1150
BYes1675
CYes1654.54545455
DYes11052.63157895
EYes11161.11111111
ANo1150
BNo1225
CNo1545.45454545
DNo1947.36842105
ENo1738.88888889
AYes0150
BYes0337.5
CYes0654.54545455
DYes0421.05263158
EYes0844.44444444
ANo0150
BNo0562.5
CNo0545.45454545
DNo01578.94736842
ENo01055.55555556

I wrote following code :

proc report data=book1   ;

column group state  value, (Frequency ColPercent) ;

define group / "Group" left order;

define state / "State" center ;

define value/ "Response" center across;

define Frequency / "Counts" center format=3.;

define ColPercent / "Percent" center format=5.1;

title;

run;

Procedure is producing following table

Response
NoYes
GroupStateCountsPercentCountsPercent
A1..150
1150..
0..150
0150..
B1..675
1225..
0..337.5
0562.5..
C1..654.5
1545.5..
0..654.5
0545.5..
D1..1052.6
1947.4..
0..421.1
01578.9..
E1..1161.1
1738.9..
0..844.4
01055.6..

However, I want table in following format:

Response
NoYes
GroupStateCountsPercentCountsPercent
A1150150
0150150
B1225675
0562.5337.5
C1545.5654.5
0545.5654.5
D1947.41052.6
01578.9421.1
E1738.91161.1
01055.6844.4

So I want value of response (count and percent) for each state in a single line. For some reason PROC report is using two lines for same group. I tried using dummy variable bu it did not work out.

I would appreciate your help.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  To collapse rows (summarize your groups), which is what you want, change your usage of ORDER to GROUP in the DEFINE statements for GROUP and STATE -- otherwise, you are getting the default of DISPLAY for STATE and that is preventing anything from being summarized (or collapsed down to 1 row).

  Again, there is a really, really good documentation topic called "How PROC REPORT Builds a Report" that describes the "side effect" of DISPLAY (the default for character), ORDER and GROUP usages.

cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  To collapse rows (summarize your groups), which is what you want, change your usage of ORDER to GROUP in the DEFINE statements for GROUP and STATE -- otherwise, you are getting the default of DISPLAY for STATE and that is preventing anything from being summarized (or collapsed down to 1 row).

  Again, there is a really, really good documentation topic called "How PROC REPORT Builds a Report" that describes the "side effect" of DISPLAY (the default for character), ORDER and GROUP usages.

cynthia

san134
Calcite | Level 5

Thanks for your help. I will read the documentation you suggested.

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
  • 2 replies
  • 729 views
  • 0 likes
  • 2 in conversation