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));

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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