如何通过SAS(SAS Studio/SSOD)用纯代码解压文件并指定目录或提取单个文件
Since you're using the cloud-hosted SAS Studio (SSOD), which runs on a Linux backend, you can build on the pipe method you started with to control extraction paths or pull specific files from your zip archive.
Specify a Custom Output Directory
The unzip command includes a -d flag to define exactly where your extracted files go. First, make sure your target directory exists (you can create it directly from SAS if it doesn't):
/* Create the output directory (and parent folders if needed) */ data _null_; infile "mkdir -p /project/output/my_unzipped_files" pipe; input; put _infile_; run; /* Unzip all files to the specified directory */ data _null_; infile "unzip /project/input/file.zip -d /project/output/my_unzipped_files" pipe; input; put _infile_; /* Prints command output/errors for debugging */ run;
The -p flag in mkdir ensures any missing parent directories are created automatically, so you don't have to make them one by one.
Extract a Single File from the Zip
To pull just one specific file from the archive, add the relative path of the file (as it appears inside the zip) to the unzip command:
/* Extract only "sales_data.csv" to the target directory */ data _null_; infile "unzip /project/input/file.zip sales_data.csv -d /project/output/my_unzipped_files" pipe; input; put _infile_; run;
If the file is nested inside a folder within the zip, include that folder path too (e.g., internal_folder/sales_data.csv).
Debugging Tip
Your original put _infile_ statement is really useful—it prints any output or error messages from the unzip command to the SAS log. This helps you spot issues like missing files, incorrect paths, or permission problems quickly.
内容的提问来源于stack exchange,提问作者TheYeti

