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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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

8 REPLIES 8
Shmuel
Garnet | Level 18

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;

TomKari
Onyx | Level 15

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;

Shmuel
Garnet | Level 18

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.

TomKari
Onyx | Level 15

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

 

Shmuel
Garnet | Level 18

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

 

TomKari
Onyx | Level 15

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

Ksharp
Super User
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;

TomKari
Onyx | Level 15

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

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
  • 8 replies
  • 14467 views
  • 4 likes
  • 3 in conversation