Hi! I am running SAS in CAS (Cloud Analytic Services). The SAS format IB4. is available there.
In my SAS program integer numbers are converted from character form into numeric form, many times. See example:
proc format;
value testf 0-10 = "1"
11-20 = "2"; /** etc. */
run;
This is used in a Data step: nnewval = INPUT( PUT(nval, testf.), 2.);
The part INPUT(PUT) is executed MANY, MANY times, so I want to use SAS formats like IB8.
However this is NOT supplied in CAS SAS.
Is there any other "integer binary" format that can be used?
My thought: In the right hand side of the format definition, do not write the character integer,
but rather a binary representation of the integer. That takes slightly more time in the creation of the format.
In the next step, when using the format, the INPUT will be somewhat faster, since 2. is replaced by an "integer format".
I tested this in WPS SAS, with IB8. The computations were speeded up. It was worth the extra programming!
Many thanks in advance for any suggestions.
CAS SAS is great to use!
/Br Anders
Note that SAS/Studio is just an interface you can use to compose and submit SAS code. You can use it to connect to VIYA and Base SAS installations.
So PIB will create strings that contain binary representations of positive (unsigned) integers. So all of the bits are used for the value of the number instead of reserving one bit to indicate that the number is negative. That means you can use PIB1. to store integers from 0 to 255 in a one byte character string. Or PIB4. to store integers from 0 to 256**4-1 in a four byte character string.
Not sure what value it will unless you are trying to recreate some binary file format for exchange with some other application.
Be careful about using the IB8. format. Base SAS uses 8 byte floating point numeric data, which is only capable of storing 15 significant digits. If you try to convert one of these numbers using IB8., the result might be inaccurate.
Hi! First of all: I use SAS Studio - which is in Linux. (NOT CAS - I was quite wrong). My falut! Mea culpa!
Your comment is QUITE good!
I will look into that!
Many thanks Anders
I don't understand why you need the IB format. How would that help?
It looks like you are just dividing by 10.
nnewval = ceil(nval/10);
Informats convert text to values.
Formats convert values to text.
If you want to move from text to numbers you can use an INFORMAT.
If you want to move from numbers to text you can use a FORMAT.
If you want to move from text to text you can use either.
If you want to move from numbers to numbers then you either need to use your INPUT(PUT()) sandwich or define a function.
But in any case I cannot see how the IB format would be of any value.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.