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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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