Hello,
I have a xlsx file of sales_order which I have imported in SAS.
Customer_Id | Viewed | Cart Additions | Revenue | Order |
1 | 3 | 1 | 0 | 0 |
39 | 0 | 0 | 8100 | 1 |
40 | 0 | 0 | 660 | 1 |
47 | 1 | 1 | 0 | 0 |
55 | 1 | 0 | 0 | 0 |
64 | 13 | 9 | 808 | 1 |
84 | 2 | 1 | 550 | 1 |
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!
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
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.
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 ._
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!
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.
Ready to level-up your skills? Choose your own adventure.