BookmarkSubscribeRSS Feed
GPatel
Pyrite | Level 9

Given Data A; would like to have output shown below either in PDF/RTF file format. Any help?  


data a;
input ID $ a b c d e f g h;
cards;
ABC 1 2 3 4 5 6 7 8
XYZ 4 3 2 1 8 7 6 5
;
run;

 

Output PDF/RTF :

 

ABC      1     2    3    4
            (5)  (6)  (7)  (8)
XYZ      4     3    2    1
            (8)  (7)  (6)  (5)

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  What code have you tried?? PROC PRINT, PROC REPORT, PROC TABULATE? Other? It might be possible with data manipulation to create a report format that will work for you as you show, but that would probably involve at least a data step and then PROC REPORT.

 

  It's useful to see your data, but would be also useful to know what you've already tried.

 

Cynthia

GPatel
Pyrite | Level 9

Thanks Cynthia for your response.


data a;
input ID $ a b c d e f g h;
cards;
ABC 1 2 3 4 5 6 7 8
XYZ 4 3 2 1 8 7 6 5
;
run;
data _null_;
set a;
x='(';
y=')';
xhy=cats(x,h,y);
xey=cats(x,e,y);
xfy=cats(x,f,y);
xgy=cats(x,g,y);
by id notsorted;
file print notitle;
if (first.id or last.id) then do;
Put @10 id @20 a @35 b @50 c @65 d /
@20 xey @35 xfy @50 xgy @65 xhy
;
end;
run;

Cynthia_sas
SAS Super FREQ

Hi:

  Using PUT statements will not work as you envision for PDF or RTF output. Basically when you start, you have 1 row per ID, but your report only has 4 columns going across. If you want "nice" PDF or RTF output, you'll have to move away from PUT statements and use the PUT function to get the parentheses on row 2 for each ID. Then, use PROC REPORT for reporting. I envisioned something more like this, where the DATA step does the restructure and then PROC REPORT just needs to display the records. 

 

  I show HTML output in my screen shot, but you can easily create RTF or PDF output by putting an ODS "sandwich" around the PROC REPORT step (and only the PROC REPORT step):

ods pdf file='c:\temp\final_report.pdf';

...insert REPORT code here;

ods pdf close;

or

ods rtf file='c:\temp\final_report.rtf';

...insert REPORT code here;

ods rtf close;

 

Here's my approach.

restructure_data_then_report.png

 

Hope this gives you an alternate idea for a solution.

Cynthia

 

anirdesh
Calcite | Level 5

Thanks Cynthia. Appreciated your efforts, time and elegant solution. 

 

Your solutions is accepted.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 451 views
  • 1 like
  • 3 in conversation