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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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