How to troubleshoot high disk consumption in a SAS® 9.4 Windows environment


A large or long-running job on a Windows PC or a Windows server might fail due to insufficient disk space. As a result, an error similar to the following occurs:

ERROR: Insufficient space in file ...

ERROR: There is not enough WORK disk space to store the results of an internal sorting phase.

In this scenario, it is crucial to know the pattern and timing of the issue in order to begin troubleshooting the underlying SAS code or add more resources.

Locate the Problem

Along with the long-running job, run the following PowerShell script:

$Drive = "C"
$OutputFile = "C:\Temp\Drive_Usage_Log.csv"

# Ensure output directory exists
If (!(Test-Path "C:\Temp")) { New-Item -ItemType Directory -Path "C:\Temp" }

# Initialize CSV header if it does not exist
if (!(Test-Path $OutputFile)) {
    "Timestamp,TotalSize_GB,FreeSpace_GB,PercentFree" | Out-File -FilePath $OutputFile -Encoding utf8
}

# Define the target run duration (24 hours from right now)
$EndTime = (Get-Date).AddHours(24)

# Run continuously until the 24-hour mark is reached
while ((Get-Date) -lt $EndTime) {
    $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
   
    # Query the specific drive using Get-CimInstance's -Filter parameter
    $DiskInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='${Drive}:'"

    if ($DiskInfo) {
        $TotalGB = [Math]::Round($DiskInfo.Size / 1GB, 2)
        $FreeGB = [Math]::Round($DiskInfo.FreeSpace / 1GB, 2)
        $PercentFree = [Math]::Round(($DiskInfo.FreeSpace / $DiskInfo.Size) * 100, 2)

        "$Timestamp,$TotalGB,$FreeGB,$PercentFree" | Out-File -FilePath $OutputFile -Append -Encoding utf8
    }

    # Set your sleep interval:
    Start-Sleep -Seconds 15
}

This script runs for 24 hours. Make sure that the problematic SAS job and this script are the only running programs on the target drive (variable $Drive in the code above).

After 24 hours, review the result (Drive_Usage_Log.csv).

The CSV file should look similar to the following (that is, a 15-second interval that results in 4 records per minute):

CSV file with a 15-second interval that results in 4 records per minute

Easily locate the issue either by scrolling down or creating a graph:

Rows in the CSV file with the issue.

Graph created from the CSV file

In this example, the job consumes a certain amount of disk, but releases only one third, which causes only the job to consume the entire disk space.

Next Steps

Now that you know where to look, you can make appropriate changes to the code so that unused disk space is released.