Good moring, everyone:
I have one SAS data set. One variable is "Value", and it's Characteristic. I would like to change it to numerical. Also, I would like to change two digital decimals. Some of my "Value" are list below. I think it should be used input function, but how to format them?
1. 53.6
2. 100
3. 8
4. 45238962
Thanks.
I posted how to do basically that.
data value;
input value:$16. type :$1.;
length formatted_value $16;
select(type);
when('O','C','U') formatted_value = putn(input(value,f16.),'F',16,2);
when('N','D') formatted_value = value;
otherwise;
end;
cards;
53.6 O
100 O
8 O
45238962 N
;;;;
run;
proc print;
run;
I forget to say, Row 1-3 are two decimal. But row 4 will be the same, no decimal.
I interpret your question as.
data value;
input value:$16.;
d = ifn(_n_ in(1:3),2,0);
length formatted_value $16;
formatted_value = putn(input(value,f16.),'F',16,d);
cards;
53.6
100
8
45238962
;;;;
run;
proc print;
run;
do
new_value = input(value,W.);
where W corresponds to the length of value; if you want to replace value, do
drop value;
rename new_value = value;
I have 454 observations in "Values", the format I list are scattered in this "Value" variable.
You need a way communicate the FORMAT for each line. Show more data with IDs for the rows.
The numbers from row 1-3 are corrospored to "O" of variable "Type", the number from row 4 are corrospored to "N" of variable "Type".
data value;
input value:$16. type :$1.;
d = ifn(type eq 'O',2,0);
length formatted_value $16;
formatted_value = putn(input(value,f16.),'F',16,d);
cards;
53.6 O
100 O
8 O
45238962 N
;;;;
run;
proc print;
run;
Hi:
Could you explain to me what is the mean for f16. and 'F' standing for? I'm lost for the code of when('O','C','U') formatted_value = putn(input(value,f16.),'F',16,2); ?
Thanks.
If my data is list below, how could I go from there? I would like to keep two decimal for type "O", "C" and "U", and keep the same for type "N" and "D".
53.6 O 100 C 8 U 45238962 N 618945 D
I posted how to do basically that.
data value;
input value:$16. type :$1.;
length formatted_value $16;
select(type);
when('O','C','U') formatted_value = putn(input(value,f16.),'F',16,2);
when('N','D') formatted_value = value;
otherwise;
end;
cards;
53.6 O
100 O
8 O
45238962 N
;;;;
run;
proc print;
run;
Also, the result I run is still in Char., not Num.
A single column in a SAS dataset may only have one SAS display format applied.
If you are going to print these values it may be that you can use a custom format for ranges of values that will make you happy once the values are converted to numeric.
Perhaps something like:
proc format ;
value MixedDecimals
0 - 1000 = [F8.2]
1000 < - high = [best12.];
run;
/* the range I picked is pretty arbitrary as I do not know what your rule for range of value might be to force the decimal appearance
Note: with this format if your large values have decimals they will be displayed. If that is not wanted then replace Best12. with F12.0*/
Then print or other display using MixedDecimals format.
Proc print data=want;
var NumericValue;
format NumericValue MixedDecimals.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.