BookmarkSubscribeRSS Feed
J3ff
Calcite | Level 5

I am trying to read a V8 transport file into my work library using %XPT2LOC, but receive an error in the log. R does not have any issue reading the file using haven::read_xpt().

 

PROC SETINIT and PRODUCT_STATUS Information:

Operating System:   SUN 64  .
For Base SAS Software ...
   Custom version information: 9.4_M3
   Image version information: 9.04.01M3P060315
For SAS/STAT ...
   Custom version information: 14.1
For SAS/GRAPH ...
   Custom version information: 9.4_M3
For SAS/Secure 168-bit ...
   Custom version information: 9.4_M2
For High Performance Suite ...
   Custom version information: 2.2_M4

SAS Code:

options nocenter ps=max validvarname=any ls=170;

%xpt2loc(filespec='FULL_PATH/name.xpt',
         memlist=pp);

proc contents data=pp;
run;

Log:

25         options nocenter ps=max validvarname=any ls=170;
26         
27         %xpt2loc(filespec='FULL_PATH/name.xpt',
28                  memlist=pp);
NOTE: Format XPRTFLT has been output.
NOTE: Informat XPRTFLT has been output.
NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
NOTE: The data set WORK.CNTLIN has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.08 seconds
      cpu time            0.07 seconds
NOTE: There were 1 observations read from the data set WORK.CNTLIN.
NOTE: 0 observations with duplicate key values were deleted.
NOTE: The data set WORK.CNTLIN has 1 observations and 4 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.02 seconds
      cpu time            0.02 seconds
NOTE: Format $MEMWANT has been output.
NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
NOTE: There were 1 observations read from the data set WORK.CNTLIN.
NOTE: Deleting WORK.CNTLIN (memtype=DATA).
NOTE: PROCEDURE DELETE used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
NOTE: UNBUFFERED is the default with RECFM=N.
NOTE: The infile 'FULL_PATH/name.xpt' is:
      Filename=FULL_PATH/name.xpt,
      Owner Name=root,Group Name=datalib,
      Access Permission=-rw-r--r--,
      Last Modified=11Dec2024:09:57:58,
      File Size (bytes)=683200
NOTE: The file METADATA is:
      Filename=/opt/tmp2/SAS_workAC2B00001EE5_stats1/#LN00014,
      Owner Name=jnichols,Group Name=users,
      Access Permission=-rw-rw----,
      Last Modified=16Dec2024:10:17:28

NOTE: The file INPTSTMT is:
      Filename=/opt/tmp2/SAS_workAC2B00001EE5_stats1/#LN00013,
      Owner Name=jnichols,Group Name=users,
      Access Permission=-rw-rw----,
      Last Modified=16Dec2024:10:17:28
NOTE: 32 records were written to the file METADATA.
      The minimum record length was 1.
      The maximum record length was 105.
NOTE: 25 records were written to the file INPTSTMT.
      The minimum record length was 3.
      The maximum record length was 43.
NOTE: DATA statement used (Total process time):
      real time           0.20 seconds
      cpu time            0.20 seconds
NOTE: The file SASCODE is:
      Filename=/opt/tmp2/SAS_workAC2B00001EE5_stats1/#LN00016,
      Owner Name=jnichols,Group Name=users,
      Access Permission=-rw-rw----,
      Last Modified=16Dec2024:10:17:28
NOTE: The infile INPTSTMT is:
      Filename=/opt/tmp2/SAS_workAC2B00001EE5_stats1/#LN00013,
      Owner Name=jnichols,Group Name=users,
      Access Permission=-rw-rw----,
      Last Modified=16Dec2024:10:17:28,
      File Size (bytes)=485
NOTE: The infile METADATA is:
      Filename=/opt/tmp2/SAS_workAC2B00001EE5_stats1/#LN00014,
      Owner Name=jnichols,Group Name=users,
      Access Permission=-rw-rw----,
      Last Modified=16Dec2024:10:17:28,
      File Size (bytes)=807
NOTE: 56 records were written to the file SASCODE.
      The minimum record length was 1.
      The maximum record length was 105.
NOTE: 25 records were read from the infile INPTSTMT.
      The minimum record length was 3.
      The maximum record length was 43.
NOTE: 32 records were read from the infile METADATA.
      The minimum record length was 1.
      The maximum record length was 105.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds
NOTE: Fileref METADATA has been deassigned.
NOTE: Fileref INPTSTMT has been deassigned.
38        +informat PPSEQ  .12 ;
                           ___
                           265
48        +informat PPSTRESN  .12 ;
                              ___
                              265
55        +informat VISITNUM  .12 ;
                              ___
                              265
ERROR 265-185: The decimal specification of 12 must be less than the width specification.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. This might cause NOTE: No observations in data set.
WARNING: The data set WORK.PP may be incomplete.  When this step was stopped there were 0 observations and 21 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds
NOTE: Fileref SASCODE has been deassigned.
85         
86         proc contents data=pp;
87         run;

SAS Universal Viewer

J3ff_0-1734362438150.png

Header Information as viewed in Notepad++

J3ff_1-1734362549877.png

 

3 REPLIES 3
Tom
Super User Tom
Super User

How was the file created? Was it created by SAS or some other software? What other software?

 

Did you move the file from one machine to another? Are you sure the move treated the file as BINARY file?  If you used FTP or other file transfer and it decided to insert or remove CR characters from the file that would corrupt it.  It it tried to transcode the file from one encoding to another that would corrupt the file.

 

When XPT2LOC reads the variable descriptions from that file the INFORMAT associated with the variable is invalid.  It appears to have decimal places set to 12 and width set to zero.  So the SAS code that the macro generates to read the data is invalid, hence the error you see in the LOG. Since R doesn't use SAS informats that is probably why R does not mind that the file has gibberish for the INFORMAT setting.

 

You could try seeing if this macro can read the file.

 https://github.com/sasutils/macros/blob/master/xport2sas.sas

 

Even if it gets a similar error perhaps you could use the SASCODE= optional parameter to the macro to tell it where to save the SAS code it generated to read the file.  Then you could try copying that code and tweaking the formats/informats and see if you can get it to work.

 

If the data is not sensitive you could share a copy of the file and others can try examining it.

J3ff
Calcite | Level 5

Thank you Tom for you quick response.

 

The dataset was provided by our client and I am not sure how the file was created.

 

While the XPT2SAS macro did produce similar errors to the XPT2LOC macro, I was able to use the code written with the SASCODE option with the informat lines removed to successfully read the V8 xpt.

Tom
Super User Tom
Super User

You should probably ask them to remake the file.   It was probably a user error that attached an invalid format specification to the variable.

 

There is really no need to attach any INFORMAT to variables that are already in a dataset.  The INFORMAT is used when converting values from text, like when reading in data from a text file.  So it will not be used at all when reading in data from an existing dataset.

 

And there is usually never any need to use an INFORMAT that has decimal places specified.  That is only used when you want SAS to imply a decimal point for characters strings that do not have one.  It was common in the old days to save one character when punching your data onto 80 column cards.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1007 views
  • 0 likes
  • 2 in conversation