BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

in proc report, or with ODS.  Given a Column with numeric format,  is it possible to change a few specified cells to character, and input a character string?

specifically,  replace all 0's or . to '--'?

Options Missing='--' does not work as it will only accept a single character.

I have been able to have 2 or more numeric formats in a column, but am unable to convert some cells to character.

I have tried the following. (also tried ODS escapechar with no luck)

 

data Temp1;
input Round $ Var1 Var2 Var3 Var4;
datalines;
Var1 0 1000 2000 3000
Var2 1111 0 2222 3333
Var3 1234 2345 0 3456
Var4 1122 2211 3322 0
;
run;

ODS RTF File="&FilePath.\Testing.rtf";
ODS ESCAPECHAR='^';
proc report data=temp1;
columns Round var1 var2 var3 var4;
define Round / display;
define Var1 / analysis;
define Var2 / analysis;
define Var3 / analysis;
define Var4 / analysis; 
compute Var1;
if Var1=0 then do;
call define(_Col_,'format','$10.');
Var1='--';
end;
if Var1 ^=0 then do;
call define (_Col_,'format','Comma10.0');
end;

endcomp;
run;
ODS RTF CLose;

 

 

1 REPLY 1
Reeza
Super User

Consider a custom format instead.

 

data Temp1;
input Round $ Var1 Var2 Var3 Var4;
datalines;
Var1 0 1000 2000 3000
Var2 1111 0 2222 3333
Var3 1234 2345 0 3456
Var4 1122 2211 3322 0
;
run;

proc format;
 value zero_fmt
 0 = '--'
 other = [comma10.0];
 run;
 
 
 proc print data=temp1;
 format _numeric_ zero_fmt.;
 run;

Results:

 

Obs	Round	Var1	Var2	Var3	Var4
1	Var1	--	1,000	2,000	3,000
2	Var2	1,111	--	2,222	3,333
3	Var3	1,234	2,345	--	3,456
4	Var4	1,122	2,211	3,322	--

@mcook wrote:

in proc report, or with ODS.  Given a Column with numeric format,  is it possible to change a few specified cells to character, and input a character string?

specifically,  replace all 0's or . to '--'?

Options Missing='--' does not work as it will only accept a single character.

I have been able to have 2 or more numeric formats in a column, but am unable to convert some cells to character.

I have tried the following. (also tried ODS escapechar with no luck)

 

data Temp1;
input Round $ Var1 Var2 Var3 Var4;
datalines;
Var1 0 1000 2000 3000
Var2 1111 0 2222 3333
Var3 1234 2345 0 3456
Var4 1122 2211 3322 0
;
run;

ODS RTF File="&FilePath.\Testing.rtf";
ODS ESCAPECHAR='^';
proc report data=temp1;
columns Round var1 var2 var3 var4;
define Round / display;
define Var1 / analysis;
define Var2 / analysis;
define Var3 / analysis;
define Var4 / analysis; 
compute Var1;
if Var1=0 then do;
call define(_Col_,'format','$10.');
Var1='--';
end;
if Var1 ^=0 then do;
call define (_Col_,'format','Comma10.0');
end;

endcomp;
run;
ODS RTF CLose;

 

 


 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 508 views
  • 2 likes
  • 2 in conversation