BookmarkSubscribeRSS Feed
art297
Opal | Level 21

I'm attempting to read a set of jpg files.  They all start off with the same characters, but I've been unable to correctly read one file.

As a test I tried to read the characters in one at a time.  The one file that is giving me problems has the following representation in hex:


FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60 00 60 00 00 FF E1 5C 1C


the other files, for which I don't have problems, start off with:


FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60 00 60 00 00 FF E1 5C 22


In this case of the first file, reading in 1 character at a time, it only reads FF D8 FF, then skips directly to E1 (i.e., the 22nd character).


Anyone have a clue?

4 REPLIES 4
Tom
Super User Tom
Super User

Art - Can you post your code?  I did not have trouble reading those characters.

data _null_;

  do filename='file1.dat','file2.dat';

    file dummy filevar=filename recfm=f lrecl=1;

      do i=1 to 24 ;

        input char $hex2. +1 @;

        put char $char1. ;

      end;

      input;

  end;

  stop;

cards;

FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60 00 60 00 00 FF E1 5C 1C

FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 60 00 60 00 00 FF E1 5C 22

run;

data _null_;

  infile 'file1.dat';

  input; put _infile_ $hex48.;

  infile 'file2.dat';

  input; put _infile_ $hex48.;

run;

FFD8FFE000104A46494600010101006000600000FFE15C1C

FFD8FFE000104A46494600010101006000600000FFE15C22

NOTE: 1 record was read from the infile 'file1.dat'.

      The minimum record length was 24.

      The maximum record length was 24.

NOTE: 1 record was read from the infile 'file2.dat'.

      The minimum record length was 24.

      The maximum record length was 24.

art297
Opal | Level 21

Tom,

The following is my test code:

%let path=c:\art\;

filename indata pipe "dir &path.*.jpg /b";

data test (keep=val counter foundit fname);

  length fil2read fname $80;

  infile indata truncover;

  informat f2r $50.;

  input f2r;

  fil2read="&path."||f2r;

  done=0;

  foundit=0;

  counter=0;

  infile dummy filevar=fil2read RECFM=f lrecl=1;

  fname=fil2read;

  do while(not done);

    input VAR1 $char1.;

    counter+1;

    val=input(var1,pibr2.);

    if var1 eq 'E' then foundit=1;

    output;

    if counter eq 30 then done=1;

  end;

run;

art297
Opal | Level 21

Tom (and anyone else who might be interested),

Upon running your code on my actual files I ended up seeing the same incorrect data.  As it turned out, the files I had been trying to analyze had been corrupted by MS.  I.e., in adding a subject line to each jpg, using MS's windows explorer, the files no longer followed the exif rules on which my analysis was based.

Art

Ksharp
Super User

Art. Maybe you can try to use another informat $phex.

filename jpg 'c:\logo.jpg';

data temp;

infile jpg ;

input x  $phex. @@;

if _n_ =100 then stop;

run;

Ksharp

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 Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1313 views
  • 3 likes
  • 3 in conversation