Wrap text in variable for proc report purpose

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Wrap text in variable for proc report purpose

Hello,

I have a problem to wrap text for long variable. My aim is to obtain new variable with inserted char(i.e. "*") to split the variable in proc report. I try to use this code, but it still doesn't work. Could you please advice?

data x;

set sashelp.afmsg(keep=text);

length newline $ 1000;

newline = '';

len = 0; * Length of string begining from last *

nwords = countw(text, ' ');

* count loop;

do count = 1 to nwords;

            word = scan(text, count, ' ');

            if len + 1 + length(word) > 30 then do;

                        * append word and if >30 then insert '*';

                        newline = newline || '*' || word;

                        len = length(word);

                        end;

            else do;

            * if <30 then we do not required append *;

            newline = newline || ' ' || word;

            len = len + length(word) + 1;

            end;

end;

run;


Accepted Solutions
Solution
‎04-09-2013 02:38 AM
Occasional Contributor
Posts: 9

Re: Wrap text in variable for proc report purpose

I am aware that PROC REPORT has build in split option. My problem is when 2 columns is combined and must be displayd as one column and second column must have two spaces from the left. See example below:

COL1: OTHER

COL2:THIS IS EXAMPLE WHY WRAPPING IS NEEDED

COMBINED COL:

OTHER

  THIS IS EXAMPLE

  WHY WRAPPING

  IS NEEDED

So my intention is to append two spaces and star: "  *" next I will use split, flow options to automatically wrap text in PROC REPORT.

Everything was fine in above example, but strip function should be added to newline:

newline=strip(newline) || "*  "|| strip(word);

Now it works correctly!

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Wrap text in variable for proc report purpose

This program

http://devenezia.com/downloads/sas/samples/split-into-words.sas

Uses the approach of inserting split charcters.

Super User
Posts: 5,516

Re: Wrap text in variable for proc report purpose

Just checking ... are you aware that PROC REPORT has a WRAP option as part of the column definitions?  It is capable of wrapping text without you having to split it.

Respected Advisor
Posts: 3,799

Re: Wrap text in variable for proc report purpose

Posted in reply to Astounding

Good point!

Back in the day when everything was .LST I used to do the splits so I could count them and control pagination.

Super User
Posts: 5,516

Re: Wrap text in variable for proc report purpose

Posted in reply to data_null__

Yes, back in the good old days when PROC REPORT didn't exist and data_null_; was the only choice!  :smileylaugh:

Respected Advisor
Posts: 3,799

Re: Wrap text in variable for proc report purpose

Posted in reply to Astounding

No the good old days when PROC REPORT did exist but ODS did not.

Solution
‎04-09-2013 02:38 AM
Occasional Contributor
Posts: 9

Re: Wrap text in variable for proc report purpose

I am aware that PROC REPORT has build in split option. My problem is when 2 columns is combined and must be displayd as one column and second column must have two spaces from the left. See example below:

COL1: OTHER

COL2:THIS IS EXAMPLE WHY WRAPPING IS NEEDED

COMBINED COL:

OTHER

  THIS IS EXAMPLE

  WHY WRAPPING

  IS NEEDED

So my intention is to append two spaces and star: "  *" next I will use split, flow options to automatically wrap text in PROC REPORT.

Everything was fine in above example, but strip function should be added to newline:

newline=strip(newline) || "*  "|| strip(word);

Now it works correctly!

🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 3112 views
  • 0 likes
  • 3 in conversation