BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

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 ?

 

 

 

5 REPLIES 5
Kurt_Bremser
Super User

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.

alepage
Barite | Level 11
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 ?

Kurt_Bremser
Super User

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));
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

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)

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

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 515 views
  • 2 likes
  • 4 in conversation