I have a char column that is display different in SAS studio data viewer and printed results;
In data viewer, it shows many extra spaces between words, but if I print the variable, it looks fine.
In data viewer
Result from proc print:
Look at the space between "Master" and "vs". Could someone tell me why it's like this?
Thanks!
I got it.
Extra spaces exist in data set and they can be removed by "compbl" function.
ODS html may automatically call "compbl" before printing.
Your problem is that you are using ODS to print your results. If you print to the normal text output you won't have that problem. Example:
data test;
input string $50.;
cards;
one two
one two
one two
one two
one two
;
proc print;
run;
Normal listing output:
Obs string 1 one two 2 one two 3 one two 4 one two 5 one two
Picture of what ODS produces:
Perhaps there is a STYLE option that will preserve the spaces between "words", but I could not find it.
Thank you!
I use SAS Enterprise7.15.
When I print results to HTML format, the spaces will be removed. If I print to other formats, then spaces won't be removed
Html:
rtf:
It seems that the display is controlled by neither data format nor style sheet.
Tom,
The STYLE option you are looking for is "ASIS=ON".
data test;
input string $50.;
cards;
one two
one two
one two
one two
one two
;
proc print style(column)={asis=on};
run;
I got it.
Extra spaces exist in data set and they can be removed by "compbl" function.
ODS html may automatically call "compbl" before printing.
@Smurf wrote:
I got it.
Extra spaces exist in data set and they can be removed by "compbl" function.
ODS html may automatically call "compbl" before printing.
If the goal is to remove the extra spaces then COMPBL() is a good choice. Be careful that some of that extra space are other invisible characters that COMPBL() will not remove. Such non-breaking space 'A0'x or tab '09'x.
It is not so much as HTML calling COMPBL() but just the nature of how HTML pages works. If you build an HTML page by hand it will flow text into neat paragraphs for you. If you want it to preserve white spaces you have to add extra code into the HTML.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.