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;
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 program
http://devenezia.com/downloads/sas/samples/split-into-words.sas
Uses the approach of inserting split charcters.
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.
Good point!
Back in the day when everything was .LST I used to do the splits so I could count them and control pagination.
Yes, back in the good old days when PROC REPORT didn't exist and data_null_; was the only choice! :smileylaugh:
No the good old days when PROC REPORT did exist but ODS did not.
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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.