BookmarkSubscribeRSS Feed
sanalitics
Obsidian | Level 7

Below is the simple proc report query, Attached is the output of the query and what is further expected from the proc report for a standard reporting format

data test;

Name="sas";

Rank=1;

loc="a";

run;

proc report data=test;

column ("test" "test1" Name rank ) ("test" loc);

run;

Kindly assist with the appropriate proc report option to achieve the required reporting format.


Proc Report.jpg
5 REPLIES 5
Reeza
Super User

Looks like it may not have been possible a couple of years ago via Proc Report, but is via proc tabulate.

Depends on your data and actual report I suppose.

Link to old post:

sanalitics
Obsidian | Level 7

Dear Reeza,

Thank you for the response, But a solution using proc report is what was expected as tabulate is mostly for the classification and

aggregations.

Considering there are no numeric variables and only text variables, Proc report would keep things simple with options to add our customized title and create a table kind of layout...

let us take an example:

data test;

input name1 $ name2 $ name3 $ name4 $ ;

cards;

A1 A2 A3 A4

A11 A22 A33 A44

;

run;

proc report data=test;

column ("Head 1" name1 ("Head11" name2)) name3 name4;

run;

Attached is the actual output and expected output ... let me know if you could help with relevant solution using any procedure.

Thanks again for all your efforts on investigating.

Proc Report Output.jpg

Cynthia_sas
SAS Super FREQ

Hi:

  PROC REPORT writes every "Header" row separately from every other header row. So it will not "span" header rows as you show in your desired/expected output. Your "Head1" is making a separate header row. So if you do not put any text above name3 and name4 at the same level as Head1, then you will get an empty cell on header row 1. Then you have header row 2, with Head11 above Name2. Again, you have designed your headers so that Head11 needs a whole row. Just as there is an empty cell above name1's header, there is an empty space in the header row above name3 and name 4. Then you have your final header row with the headers name1, name2, name3 and name4 -- at the point in time when PROC REPORT is writing the last header row, it can't "go back" and change the rows about name3 and name4 to spanning headers such as you show. PROC REPORT writes every header row a single row at a time, so one row has to finish before the next row starts. That is why your Actual output is what you should expect -- PROC REPORT is working as it is supposed to work. Your desired output with a spanning row header above name3 and another spanning row header above name 4 is not do-able with PROC REPORT.

cynthia

sanalitics
Obsidian | Level 7

Cynthia , Do we have any other methods/procedures to produces the desired output for the above mentioned example?

Cynthia_sas
SAS Super FREQ

Hi: Not really an "out of te box" solution. There's always post processing the report file.  If your destination is ODS RTF, then you could edit the headers in Word after the RTF file is created to merge table cells. If your destination is ODS HTML, then you could post process the HTML to make the spanning headers.

Worrying about this type of cosmetics seems overly focused on cosmetics to me. SAS is not Excel or Word. You can't merge cells just by highlighting them and selecting a menu option to merge cells. When you are writing reports you have the capabilities of each procedure's method of writing the output report. Sometimes you can change the default method to do what you want, sometimes you can't. Sometimes, you have to adjust your expectations.

The only other thing I can think of is a custom table template with custom headers. Sometimes the order that you define the headers in can cause spanning, but it is not always guaranteed. And you would have to learn PROC TEMPLATE syntx and use DATA _NULL_ to call the template. You would have to calculate your own summary lines if you wanted subtotals or grand totals. So it might be do-able, but to even find out whether it's going to work, you have a learning curve. If you are interested in pursuing this approach to see whether it will do what you want, you would need to read about PROC TEMPLATE for TABLE templates used with DATA _NULL_.

cynthia

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1381 views
  • 0 likes
  • 3 in conversation