BookmarkSubscribeRSS Feed
sri1
Obsidian | Level 7

Hi ,

 

I have the following dataset and trying to add blank spaces with nbspace function, but appears as text in output of proc report.

 

I am not sure where I am getting wrong.

 

data test;

infile cards;

input x $  x1 $;

cards;

10.1  0

0      10.2

4.5    0

;

run;

 

ods escapecahr="$";

data test2;

array arr1(2) $15 x x1;

set test;

do i= 1 to 2;

if arr1(i)=0 then arr1(i)="0${nbspace3}";

end;

run;

 

ods rtf file="C:\test.rtf";

proc report data=test2;

column x x1;

define x/display center;

define x1/display center;

run;

ods rtf close;

 

proc report output is as below:

       x                       x1

    10.1                0{nbspace3}

0{nbspace3}          10.2

    4.5                 0{nbspace3}

 

Appreciate your input.

 

Thanks

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Are you doing this to try to right justify or left justify the zeros? There are other ways to do this, and you'd be much better off if you read in X and X1 as numbers instead of characters. And I'm not sure exactly what nbspace at the end of the line will do anyway, usually you would use nbspace in the middle of text, such as this:

footnote  "Marketing Data ^{nbspace 50}  www.sas.com ";

 

Anyway, this line will not work

 

if arr1(i)=0 then arr1(i)="0${nbspace3}";

It should say

 

if arr1(i)="0" then arr1(i)="0${nbspace3}";

 

--
Paige Miller
Ksharp
Super User
if arr1(i)=0 then arr1(i)="0${nbspace3}";
==>
if arr1(i)=0 then arr1(i)="0$_$_$_";
RichardDeVen
Barite | Level 11

You can use the hard space character denoted in hex form as 'A0'x

if arr1(i)=0 then arr1(i)=cats('0', repeat('A0'x,2));

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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