Help using Base SAS procedures

Multiple lines in a PROC REPORT cell

Accepted Solution Solved
Reply
PROC Star
Posts: 1,167
Accepted Solution

Multiple lines in a PROC REPORT cell

Hi, all

 

I am using PROC REPORT, and for three columns I would like to have the cells contain multiple lines, and control where the line breaks. Here's an MS Word image of what I'm trying to get:

 

ProcReport.jpg

 

The only way I can seem to get this is to use a DATA step to physically create a long character variable, with my lines separated by <crlf> characters. So the first cell would be

LONGLINE = cats(Line1, '0d0a'x, Line2, '0d0a'x, Line3);

I'm far from an expert on PROC REPORT, but it seems to me there should be an easier way.

 

All suggestions would be appreciated!

  Tom


Accepted Solutions
Solution
‎11-20-2016 10:03 AM
Super User
Posts: 10,028

Re: Multiple lines in a PROC REPORT cell

Use escapechar instead.


 
data have;
length AllCol1Data AllCol2Data AllCol3Data $256;
AllCol1Data = cats('C1Line 1 ~n C1Line 2');
AllCol2Data = cats('C2Line 1 ~n C2Line 2');
AllCol3Data = cats('C3Line 1 ~n C3Line 2 ~n C3Line 3 ~n C3Line 4');
output;
run;
ods escapechar='~';
proc report data=have nowd;
columns AllCol1Data AllCol2Data AllCol3Data;
define AllCol1Data / display "Column 1";
define AllCol2Data / display "Column 2";
define AllCol3Data / display "Column 3";
run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,568

Re: Multiple lines in a PROC REPORT cell

Please post a sample data and criteria for the break and wanted output.

Have you tried using proc report - if positive, post your code and output;

PROC Star
Posts: 1,167

Re: Multiple lines in a PROC REPORT cell

Hi, Shmuel

 

Here's the SAS code that I am using, with the <crlf> characters. I really think there should be a way to do this without needing such a technical approach. Let me know what you think.

 

Thanks,

   Tom

 

data have;

length AllCol1Data AllCol2Data AllCol3Data $256;

AllCol1Data = cats('C1Line 1', '0d0a'x, 'C1Line 2');

AllCol2Data = cats('C2Line 1', '0d0a'x, 'C2Line 2');

AllCol3Data = cats('C3Line 1', '0d0a'x, 'C3Line 2', '0d0a'x, 'C3Line 3', '0d0a'x, 'C3Line 4');

output;

run;

proc report data=have nowd;

columns AllCol1Data AllCol2Data AllCol3Data;

define AllCol1Data / display "Column 1";

define AllCol2Data / display "Column 2";

define AllCol3Data / display "Column 3";

run;

Trusted Advisor
Posts: 1,568

Re: Multiple lines in a PROC REPORT cell

Now that I understand what are you looking for - it was a chalenge, for me, to try and find the solution.

I'm not sure it is possible but I have found some options, which may do the work when lines are realy long.

 

See next link:

http://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#n0kl4q7byk2otyn1lkw3r...

 

It seems that next code, maybe will do the work:

    proc report data have wrap named;

        columns ....

        define <col name> / display <label> width=25;   /* for 25 characters column width */

       ....

    run;

 

With the sample data I could not come to the wanted output.

Maybe someone else in the forum can help more.

PROC Star
Posts: 1,167

Re: Multiple lines in a PROC REPORT cell

Sorry, I think I mislead you with the contents of the variables. They have nothing to do with which row and column they are in, I just used those because I wanted to not disclose client data. Here's a better example. Given:

 

data have;

length AllCol1Data AllCol2Data AllCol3Data $256;

input AllCol1Data & AllCol2Data & AllCol3Data &;

cards;

A AAAA/BB/C/DD DDDDD EEE/FF FFF FF GGGGGG GG/HH

run;

 

I would like to see a PROC REPORT result of:

 

ReportXmp.jpg

 

(Note that I don't care that the line end statement is a slash; any odd character will do)

 

Tom

 

Trusted Advisor
Posts: 1,568

Re: Multiple lines in a PROC REPORT cell

You have just changed the breaking column delimiter from '0d0a'x  to '/'.

 

PROC Star
Posts: 1,167

Re: Multiple lines in a PROC REPORT cell

Ideally I would want the delimiter to be just a normal character, instead of using a <crlf> combination. But I can't find any way to make it work.

 

Tom

Solution
‎11-20-2016 10:03 AM
Super User
Posts: 10,028

Re: Multiple lines in a PROC REPORT cell

Use escapechar instead.


 
data have;
length AllCol1Data AllCol2Data AllCol3Data $256;
AllCol1Data = cats('C1Line 1 ~n C1Line 2');
AllCol2Data = cats('C2Line 1 ~n C2Line 2');
AllCol3Data = cats('C3Line 1 ~n C3Line 2 ~n C3Line 3 ~n C3Line 4');
output;
run;
ods escapechar='~';
proc report data=have nowd;
columns AllCol1Data AllCol2Data AllCol3Data;
define AllCol1Data / display "Column 1";
define AllCol2Data / display "Column 2";
define AllCol3Data / display "Column 3";
run;

PROC Star
Posts: 1,167

Re: Multiple lines in a PROC REPORT cell

Hi, @Ksharp, and thanks!

 

I must admit, I thought there would be something in the PROC REPORT syntax that would do this, but I guess there isn't.

 

Anyway, this is a much more elegant solution, and I'm completely happy giving this to my client as a suggested approach. Thanks so much!

 

Keep an eye out for my next expected problem...it'll be under the ODS community.

 

Tom

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 590 views
  • 1 like
  • 3 in conversation