I would like to convert file sizes from MB, KB to Bytes. This can of course also be done via a formula, only I have used the format sizekmg. . Now I get for certain cases that it does not work, like with size_kb_2. Does anyone know why this is not working properly?
SAS Code:
data test;
size_kb_1="32.04KB";
size_kb_2="159.61KB";
size_bytes_1 = input(size_kb_1,sizekmg.);
size_bytes_2= input(size_kb_2,sizekmg.);
run;
Output dataset test:
Note that including the number of decimal places in an INFORMAT is telling SAS to divide any strings without an explicit decimal point by that power of ten. Unless you know that the strings have expressly removed the decimal point to save one byte do not include the number of decimal places in the INFORMAT. Just specify the total width. And since INPUT() does not care if the informat width is larger than the length of the string it is reading you can just use the maximum allowed width.
sizekmg35.
Like the SIZEKMG format, the informat has a default width of 6, and therefore misses part of the string when you omit to specify a width.
So this works:
data test;
size_kb_1="32.04KB";
size_kb_2="159.61KB";
size_bytes_1 = input(size_kb_1,sizekmg12.);
size_bytes_2= input(size_kb_2,sizekmg12.);
run;
Note: do not use a fractional part in the informat unless you absolutely need it (when there's no dot in the input string, but the last x digits have to be considered as decimal fractions). A string of 1234, read with 6.2, would result in a number of 12.34.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.