SUPPORT / SAMPLES & SAS NOTES
 

Support

Problem Note 41451: Trailing blanks appear at the end of a variable when you bulk load data to Oracle

DetailsAboutRate It

SAS/ACCESS® Interface to Oracle adds trailing blanks at the end of a variable when you bulk load data to the Oracle database. The SAS® System handles reading variables of type VARCHAR this way because SAS does not have a variable-length data type. Therefore, variable values that are less than the full length of the variable are padded with blanks. For example, suppose a variable is defined with a length of 10 and you store the value ABC in the variable. What the software actually stores is the value ABC followed by seven blanks.

To remove the trailing blanks at the end of a variable, use any of the following options:

  • Use the SAS TRIMN() function after data is loaded. The TRIMN() function is passed to the Oracle database as the RTRIM() function. This conversion removes trailing blanks, but it does require additional coding and an extra step.
  • Do not use bulk loading. If you use the BULKLOAD=NO option, then no trailing blanks occur.
  • Strip the blanks by either modifying or changing the control file that is created by SAS for use by the Oracle SQL*Loader.
  • Example of a Control File

    OPTIONS (DIRECT=TRUE , ERRORS=1000000) LOAD DATA INFILE "amy_bulk.dat" "FIX 38" INTO TABLE AMY_BULK APPEND ( "ID" POSITION(1:8) DOUBLE NULLIF "ID"=BLANKS , "INFO" POSITION(9:38) CHAR "decode(:info,null,' ')" ) Table definition: Name Null? Type ----------------------------------------- -------- -------------- ID NUMBER INFO NOT NULL VARCHAR2(30)

Code examples that illustrate how to avoid the trailing blanks:

  1. In this example, the NOT NULL columns use the database default values.
    /* Sample_20100816_1: Oracle bulk loading, without trailing blanks, into NOT NULL columns. */ /* Use BULKLOAD=YES and DROP=INFO to remove columns so that the columns use database default values. */ /* Variables need to be modified. */ %let myuser=user-id; %let mypass=password; %let mypath=path-name; /* End of modified variables. */ /* Generic code. */ data test; id=1; info=''; output; id=2; info=' '; output; run; libname x oracle user=&myuser pass=&mypass path=&mypath; proc append base=x.amy_bulk(bulkload=yes bl_direct_path=no drop=info) data=test(drop=info); run; /* End of sample_20100816_1. */
  2. This example loads the data and then reloads the rejected rows (assuming that there are not too many rejected rows because of NOT NULL column issues).
       /* Sample_20100816_2: Oracle bulk loading, without trailing blanks, into NOT NULL columns. */
       /* Use BULKLOAD=YES and reload the rejected rows.                                          */
    
    
       /* Variables need to be modified. */
    %let myuser=user-id;
    %let mypass=password;
    %let mypath=path-name;
       /* End of modified variables. */
    
    
       /* Generic code */
    data test;
       length info $30.;
       id=21; info='good data'; output;
       id=22; info=''; output;
       id=23; info='     '; output;
    run;
    
    libname x oracle user=&myuser pass=&mypass path=&mypath;
    
       /* You might need to adject the file path depending on the platform used */
    proc append base=x.amy_bulk(bulkload=yes bl_datafile="c:/temp/amy_bulk.dat" bl_delete_datafile=no)
      data=test;
    run;
    
    /* End of sample_20100816_2*/

To load the rejected rows:

  1. Open a command window, and submit the command cd c:\temp.
  2. Locate the bad file and the control file.
  3. Move the bad file to a data file using, for example, the command mv BL_AMY_BULK_6.bad BL_AMY_BULK_6.dat.
  4. Modify the control file. (See Example of Control File for the original control file that is modified in this step). Add the following information to the NOT NULL columns in the new control file, as follows:
    OPTIONS (DIRECT=TRUE , ERRORS=1000000) LOAD DATA INFILE "c:/temp/amy_bulk.dat" "FIX 38" INTO TABLE AMY_BULK APPEND ("ID" POSITION(1:8) DOUBLE NULLIF "ID"=BLANKS "INFO" POSITION(9:38) CHAR "decode(:info, null, ' ')")
  5. Run the SQL&Loader utility, as follows:
    sqlldr userid=user-id/password control=BL_AMY_BULK_6.ctl
  6. Check the log file to ensure that all of the data is loaded.

Note: In case A, the KEEP= and DROP= data set options work for the APPEND procedure, with the insertion of limited columns inserted. However, the following warning is issued in the log, regardless, if you use the system options DKROCOND=NOWARN and DKRICOND=NOWARN along with the FORCE NOWARN procedure option.

'WARNING: The DROP, KEEP AND RENAME options are ignored for the BASE data set.'


Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemSAS/ACCESS Interface to OracleMicrosoft® Windows® for 64-Bit Itanium-based Systems9.1 TS1M3 SP4
Microsoft Windows Server 2003 Datacenter 64-bit Edition9.1 TS1M3 SP4
Microsoft Windows Server 2003 Enterprise 64-bit Edition9.1 TS1M3 SP4
Microsoft Windows XP 64-bit Edition9.1 TS1M3 SP4
Microsoft Windows 2000 Advanced Server9.1 TS1M3 SP4
Microsoft Windows 2000 Datacenter Server9.1 TS1M3 SP4
Microsoft Windows 2000 Server9.1 TS1M3 SP4
Microsoft Windows 2000 Professional9.1 TS1M3 SP4
Microsoft Windows NT Workstation9.1 TS1M3 SP4
Microsoft Windows Server 2003 Datacenter Edition9.1 TS1M3 SP4
Microsoft Windows Server 2003 Enterprise Edition9.1 TS1M3 SP4
Microsoft Windows Server 2003 Standard Edition9.1 TS1M3 SP4
Microsoft Windows XP Professional9.1 TS1M3 SP4
Windows Vista9.1 TS1M3 SP4
Windows Vista for x649.1 TS1M3 SP4
64-bit Enabled AIX9.1 TS1M3 SP4
64-bit Enabled HP-UX9.1 TS1M3 SP4
64-bit Enabled Solaris9.1 TS1M3 SP4
HP-UX IPF9.1 TS1M3 SP4
Linux9.1 TS1M3 SP4
Linux on Itanium9.1 TS1M3 SP4
OpenVMS Alpha9.1 TS1M3 SP4
Solaris for x649.1 TS1M3 SP4
Tru64 UNIX9.1 TS1M3 SP4
Microsoft® Windows® for x649.2 TS2M3
Microsoft Windows Server 2003 for x649.2 TS2M3
Microsoft Windows Server 20089.2 TS2M3
Microsoft Windows Server 2008 for x649.2 TS2M3
Windows 7 Enterprise 32 bit9.2 TS2M3
Windows 7 Enterprise x649.2 TS2M3
Windows 7 Home Premium 32 bit9.2 TS2M3
Windows 7 Home Premium x649.2 TS2M3
Windows 7 Professional 32 bit9.2 TS2M3
Windows 7 Professional x649.2 TS2M3
Windows 7 Ultimate 32 bit9.2 TS2M3
Windows 7 Ultimate x649.2 TS2M3
Linux for x649.2 TS2M3
OpenVMS on HP Integrity9.2 TS2M3
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.