Hi, how do you convert a variable type number to character when some values include special characters such <? e.g., p_value=<.0001.
In that case just do it yourself.
if not missing(numvar) then do;
if numvar >= 0.0001 then charvar=put(numvar,7.4);
else charvar='<0.0001';
end;
@ANKH1 wrote:
Hi, how do you convert a variable type number to character when some values include special characters such <? e.g., p_value=<.0001.
Did you mix up the direction of the conversion? If the value is numeric it cannot have any special characters.
So assuming you want to convert a character string to a number you will have to decide what to do with extra characters. Do you just want to remove them?
So you could remove specific characters:
numvar = input(compress(charvar,'<'),32.);
Or only keep digits and normal punctuation.
numvar = input(compress(charvar,'+-.','kd'),32.);
In that case just do it yourself.
if not missing(numvar) then do;
if numvar >= 0.0001 then charvar=put(numvar,7.4);
else charvar='<0.0001';
end;
Thank you!
@ANKH1 wrote:
Hi, the variable comes from an output after running proc glmm. I am getting the output to create a table with results. The output specifies ProbF as a numeric variable. Some of the values are <.0001. The issue is that if I leave the type as numeric I get the actual number e.g., 0.000054 instead of the convention of reporting a pvalue as <0.0001.
Hi @ANKH1,
You can get the formatted value with the VVALUE function, even without knowing the format. You should specify a reasonable length, though:
data want;
set have;
length char_ProbF $8;
char_ProbF=vvalue(ProbF);
run;
Do not convert it into character, better apply format pvalue6.4 which displays the value as expected
data have;
set have;
format probF pvalue6.4;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.