BookmarkSubscribeRSS Feed
mdhtrivedi
Obsidian | Level 7

Hello,

I have a xlsx file of sales_order which I have imported in SAS. 

Customer_Id ViewedCart AdditionsRevenue Order 
13100
390081001
40006601
471100
551000
641398081
84215501

 

I want to replace 0's by '*' where 0 is a numeric and '*' is a character. 

I have tried following code snippet to achieve this:-

data Online_Orders;  

    set Online_Orders;

    array nm(*) _numeric_;

    do _n_ = 1 to dim(nm);

    nm(_n_) = coalesce(nm(_n_),*);
end;

run;

But I couldn't achieve expected output. Kindly help me with this.

Thank you in advance!

 

 

3 REPLIES 3
novinosrin
Tourmaline | Level 20

I don't think it is possible to replace numeric 0's with * char. You can use formats. Or you would have to create another char array and hold all those values as text along with * that replaced your 0's

PaigeMiller
Diamond | Level 26

You can't replace a value of a numeric variable with a character value.

 

However, you could assign a format to make it appear as an asterisk, or you can assign it to be a missing value.

 

If you assign a format and make it appear as an asterisk, SAS will still do all calculations using a zero. To tell you the truth, without further explanation, I think this is a poor idea.

 

If you want to assign it a missing value, then SAS will treat the value as missing (not zero). There are "special" missing values if you want to use them, such as .A, which is treated as a missing and not a zero, and appears as the letter A when you look at it.

--
Paige Miller
Astounding
PROC Star

As you have been advised, you can't store a character value in a numeric variable.  However, you could get the zeros to print as "M" instead of "0" if you desired:

 

if nm{_n_} = 0 then nm{_n_} = .M;

 

There are 27 special missing values you can choose from:  .A through .Z as well as ._

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1503 views
  • 0 likes
  • 4 in conversation