Desktop productivity for business analysts and programmers

Replace missing values 0 by '*' using sas array

Reply
New Contributor
Posts: 3

Replace missing values 0 by '*' using sas array

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!

 

 

Super User
Posts: 2,049

Re: Replace missing values 0 by '*' using sas array

Posted in reply to mdhtrivedi

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

Respected Advisor
Posts: 3,257

Re: Replace missing values 0 by '*' using sas array

[ Edited ]
Posted in reply to mdhtrivedi

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
Super User
Posts: 6,921

Re: Replace missing values 0 by '*' using sas array

Posted in reply to mdhtrivedi

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

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 104 views
  • 0 likes
  • 4 in conversation