BookmarkSubscribeRSS Feed
IanWakeling
Barite | Level 11

Following on from my question yesterday, I am now successfully reading data from a binary file, but I can only do this with the random access style syntax along the lines of "input >n" to read something at byte position n.

 

If I try syntax like " input <8 x IEEE8.; "  to read the next 8 bytes as an IEEE double, it does not advance the file pointer, so any similar input statements that follow keep re-reading the same 8 bytes.   I have tried using a trailing @ but this makes no difference.  Is there perhaps a hold control for binary files that I am not aware of?

 

Also, is there a way of reading a block of data into a matrix, instead of reading numbers one at a time?

4 REPLIES 4
Ksharp
Super User

I remembered @art297  wrote a paper about reading binary file(a picture) , you need special informat .

Rick_SAS
SAS Super FREQ

I don't know. I have never read binary data into IML variables.

 

In my experience, it is easier to use the DATA step for operations such as this. If this is something that is one step of a larger IML program, you can use the SUBMIT-ENDSUBMIT block to call the DATA step from within PROC IML. You can even pass parameters from IML variables into the DATA step.

IanWakeling
Barite | Level 11

I think I am probably sticking with a pure IML solution as I have something that works, it's is just not quite as fast as I hoped.  The binary files are large, around 350MB to 1GB.  Each contains 5 matrices and 5 vectors (not all of which will be required), and it just seemed more efficient to read what I want directly into IML for further processing.

Rick_SAS
SAS Super FREQ

OK. One possible idea regarding the speed: If you need to run several programs on the same data, you can read the binary data into matrices once, then save them as a SAS data set (preferred) or use the STORE statement to save the matrices. If you do that, subsequent access of the data will be faster.  Of course, if you are trying to read data that are generated every morning by some non-SAS process and only analyzed by one IML program, this idea won't save you any time.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 827 views
  • 2 likes
  • 3 in conversation