BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Smurf
Obsidian | Level 7

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

Smurf_0-1705774995613.png

 

Result from proc print:

Smurf_1-1705775040306.png

 

Look at the space between "Master" and "vs".  Could someone tell me why it's like this?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Smurf
Obsidian | Level 7

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.

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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:

Tom_0-1705777909325.png

 

Perhaps there is a STYLE option that will preserve the spaces between "words", but I could not find it.

 

Smurf
Obsidian | Level 7

Thank you!

 

I use SAS Enterprise7.15.

Smurf_0-1705779154091.png

 

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:

Smurf_1-1705779196060.png

rtf:

Smurf_2-1705779237518.png

 

It seems that the display is controlled by neither data format nor style sheet.

Ksharp
Super User

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;

Ksharp_0-1705827851202.png

 

Smurf
Obsidian | Level 7
Thank you so much!
I didnot know styles worked so different on different ODS destinations.
Smurf
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

@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.

Smurf
Obsidian | Level 7
Thank you!

sas-innovate-white.png

🚨 Early Bird Rate Extended!

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.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1882 views
  • 2 likes
  • 3 in conversation