Hello,
Is there a way to first use a Unix command to the content of the zip file ?
Is there a way to read the xport file in work without having to unzip it ?
Please provide the SAS Code
Here's my script which works correctly but I need to unzip into the temp folder the use the libname xport
%let pathbebill=/dwh_actuariat/sasdata_controlled/current/be/othr/bel.prod0030.saf3fm.data;
%let fname=saf3fm_billing.zip;
%let work=%sysfunc(pathname(work));
%let path=/finsys/bicoe/users/rpnna322/Temp/;
%let outputfile=SAF3FM.XPORT;
filename oscmd pipe "unzip -d &path. -o &pathbebill./&fname. 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
libname myxport xport "&path./&outputfile.";
proc copy inlib=myxport out=work;
run;
How to read the xport file witout having to unzip it ?
From the documentation, it seems that a physical filename must be used for the target file, so you cannot use a file reference created with the ZIP option there. This means you have to unzip first.
filename oscmd pipe "unzip -l /dwh_actuariat/sasdata_controlled/current/be/othr/bel.prod0030.saf3fm.data/saf3fm_billing.zip 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
What I am getting:
Archive: /dwh_actuariat/sasdata_controlled/current/be/othr/bel.prod0030.saf3fm.data/saf3fm_billing.zip
Length Date Time Name
--------- ---------- ----- ----
297385440 07-30-2025 06:06 SAF3FM.XPORT
--------- -------
297385440 1 file
Is there a way to put the file name into a macro function and execute the next unix command in work as we may have the file name ?
You can parse the output of the unzip command for the "XPORT" word and then extract the filename:
if index(_infile_,"XPORT")
then call symputx("fname",scan(_infile_,-1));
How about something like this:
%let outputfile=SAF3FM.XPORT;
%let work=%sysfunc(pathname(WORK));
/* create a ZIP file with some content */
/* create xport file */
libname myxport xport "&work./&outputfile.";
data myxport.iris;
set sashelp.iris(rename=(Species=SPEC SepalLength=SL SepalWidth=SW PetalLength=PL PetalWidth=PW));
run;
/* copy xport file into zip */
/* in */
filename A "&work./&outputfile." lrecl=1 recfm=N;
/* out */
filename B ZIP "&work./myFile.zip" member="&outputfile." lrecl=1 recfm=N;
data _null_;
rc=fcopy("A","B");
put rc=;
run;
And then:
/* get data from the zip file */
%let path=%sysfunc(pathname(WORK));
%let outputfile=SAF3FM.XPORT;
filename C ZIP "&path./myFile.zip" member="&outputfile." lrecl=1 recfm=N;
filename D "&work./&outputfile." lrecl=1 recfm=N;
data _null_;
rc=fcopy("C","D");
put rc=;
run;
libname myxport xport "&path./&outputfile.";
proc copy inlib=myxport out=work;
run;
Bart
Not with the XPORT libref engine.
Did you try using the %XPT2LOC() autocall macro that SAS provides instead?
filename myxport zip
"/dwh_actuariat/sasdata_controlled/current/be/othr/bel.prod0030.saf3fm.data/saf3fm_billing.zip"
member="SAF3FM.XPORT"
;
%xpt2loc(filespec=myxport)
If that doesn't work then try using this macro instead
https://github.com/sasutils/macros/blob/master/xport2sas.sas
%xport2sas(myxport)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.