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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
c44rl
Fluorite | Level 6

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

6 REPLIES 6
data_null__
Jade | Level 19

This program

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

Uses the approach of inserting split charcters.

Astounding
PROC Star

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.

data_null__
Jade | Level 19

Good point!

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

Astounding
PROC Star

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

data_null__
Jade | Level 19

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

c44rl
Fluorite | Level 6

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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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