Hi,
I used an array to convert the numeric variables to character variables. None of the numeric variables had any formats associated with it but all had a length of 8. The value for non-missing numeric values was 1 and the value of missing numeric values was a period. I applied the character fomat $40. as I need to reformat the values later. However, after conversion of the numeric to character the missing values are being retained as periods and not blanks. Is there a way to have them as blanks after the conversion? Please let me know as soon as possible. Thanks.
Array _numeric(*)
var2
var3
var4
var5
var6;
Array _character(*) $ 40
var2_C
var3_C
var4_C
var5_C
var6_C
DO i=1 to dim(_numeric);
_character(i) = PUT(_numeric(i),8.);
END;
A simple change to one statement:
if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);
A simple change to one statement:
if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);
@Astounding, chance is very slim, yet possible:
data test;
input num;
char=put(num,8.);
char_1=ifc(num>.,put(num,8.),'');
char_2=ifc(not missing(num),put(num,8.),'');
cards;
100
.
._
.A
.Z
;
You can change the setting of the MISSING option. Also be careful how you convert to character. Your current use of the PUT() function will cause your character variables to have leading spaces.
2183 %let save=%sysfunc(quote(%qsysfunc(getoption(missing))));
2184 options missing=' ';
2185 data _null_;
2186 do x=0,1,.,123.456 ;
2187 c1=put(x,8.);
2188 c2=cats(x);
2189 put x= (c1 c2) (= :$quote.) ;
2190 end;
2191 run;
x=0 c1=" 0" c2="0"
x=1 c1=" 1" c2="1"
x= c1="" c2=""
x=123.456 c1=" 123" c2="123.456"
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
2192 options missing=&save;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.