1
votes

I am new to SAS and am working with a data set that deals with a numeric variable 'width'. This variable has multiple missing values which appear as '.' and I need to convert these so they appear as 'No Sample' in the results If I just converted to zero I would just do:

if width=. then do width='0';

But since I need to change it to a character I am unsure what to do.

Thanks

2

2 Answers

5
votes

Define a format and use that with your variable.

proc format ;
  value nosample
   .='No Sample'
  ;
run;
proc print data=have ;
  format width nosample.;
run;
0
votes

Would this help?

DATA testwidth; 
INPUT @1 BirthDate DATE11.
      @13 Width 8.; *Decimal and integer ages using YRDIF; 
FORMAT BirthDate DATE11. width 8.; 
DATALINES; 
01-MAR-2017 10
02-MAR-2017 9
03-MAR-2017 8
28-MAR-2017 11
30-MAR-2017 
02-JUN-2017 6
02-JUL-2017 5
;
data newds (drop=num_width);
    length width $12.;
    set testwidth(rename=(width=num_width));
    if num_width=. then width = 'NO SAMPLE';
    else width = num_width;
run;