BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AndersS
Lapis Lazuli | Level 10

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

 

Anders Sköllermo (Skollermo in English)
1 ACCEPTED SOLUTION

Accepted Solutions
AndersS
Lapis Lazuli | Level 10
Typing error: Should be "The SAS format IB4. is NOT available there."
Anders Sköllermo (Skollermo in English)

View solution in original post

9 REPLIES 9
AndersS
Lapis Lazuli | Level 10
Typing error: Should be "The SAS format IB4. is NOT available there."
Anders Sköllermo (Skollermo in English)
AndersS
Lapis Lazuli | Level 10
Hi! The title was NOT correct. This is not in CAS.
Mea culpa!

The solution i SAS Studio (running on Linux): PIB8. turned out to be the best.
I write a lot of integer numbers as characters. Later I read them from the char acyter variabl, to recreate the integer number.
Anders Sköllermo (Skollermo in English)
Tom
Super User Tom
Super User

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.

 

 

TomKari
Onyx | Level 15

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.

AndersS
Lapis Lazuli | Level 10

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

 

Anders Sköllermo (Skollermo in English)
Tom
Super User Tom
Super User

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);
AndersS
Lapis Lazuli | Level 10
Hi! When creating the user format, numeric integers are converted into character integers.
When using the format, the character numbers in the right hand side are used. But I want them as numbers. So I have to convert them back to numeric integers.
Perhaps my exampla was too simple. No I do not want to divide by 10.
Anders Sköllermo (Skollermo in English)
Tom
Super User Tom
Super User

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.

AndersS
Lapis Lazuli | Level 10
Hi! I have a long answer, but it is too long to post here. I hope I can include it in a few weeks,
Anders Sköllermo (Skollermo in English)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 9 replies
  • 1865 views
  • 1 like
  • 3 in conversation