DATA Step, Macro, Functions and more

need to change non missing observations into X

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 115
Accepted Solution

need to change non missing observations into X

I need to change non missing observations into "X" and keep missing as '.'

I used the below code

data fin(drop=i);
set qs2;
array nvar(i)  _numeric_;
do i= 1 to dim(nvar);
if nvar(i) ne . then nvar(i)= 'X';
end;
run;

 But as the values are numeric and i am converting them as character i get an error.

 

Can there be any other way in arrays to do


Accepted Solutions
Solution
‎01-23-2017 05:50 AM
Regular Contributor
Posts: 194

Re: need to change non missing observations into X

Hello,

 

You can use a format :

proc format;
value X .='.'
       other='X';
run;

proc print data=sashelp.class;
var _NUMERIC_;
format _NUMERIC_ X.;
run;

View solution in original post


All Replies
Solution
‎01-23-2017 05:50 AM
Regular Contributor
Posts: 194

Re: need to change non missing observations into X

Hello,

 

You can use a format :

proc format;
value X .='.'
       other='X';
run;

proc print data=sashelp.class;
var _NUMERIC_;
format _NUMERIC_ X.;
run;
Super User
Super User
Posts: 7,392

Re: need to change non missing observations into X

Do not however, that doesn't "change" the results, only displays them differently.  If you really want to "change" the data, then convert the column to character and then the replace should work fine

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 3 in conversation