Hi, I dont know too much about SAS, I am using cloud SAS Studio, I want to unzip an an XPT file which is more than 1 gig. Firstly i tried to unzip that xpt file to local drive, when i wanted to impot that file to SAS Studio, Msg come that more then 1gb size file could not be imported, So imported the zip file. then i tried following code,
filename inzip ZIP "/home/u63672513/Mydata/LLCP2022XPT.zip";
/* Read the "members" (files) from the ZIP file */
data contents(keep=memname isFolder);
length memname $200 isFolder 8;
fid=dopen("inzip");
if fid=0 then
stop;
memcount=dnum(fid);
do i=1 to memcount;
memname=dread(fid,i);
/* check for trailing / in folder name */
isFolder = (first(reverse(trim(memname)))='/');
output;
end;
rc=dclose(fid);
run;
/* create a report of the ZIP contents */
title "Files in the ZIP file";
proc print data=contents noobs N;
run;
Now i can see the XPT file in the work folder "/saswork/SAS_work39CD0001A26A_odaws02-apse1.oda.sas.com/SAS_work59200001A26A_odaws02-apse1.oda.sas.com",
Now i want to copy the XPT file to the folder (/home/u63672513/Mydata), need expert help, please
Looks like you have the first part of this blog post followed, but not the second part about copying the file out. In the post they're using a WORK library to copy it out, but you should use a local folder, so change the 'xl' reference in the code to the location you want to save the file.
Maybe something like this:
/* identify a temp folder in the WORK directory */
filename xl "/home/USERNAME/....../LLCP2022XPT.xpt" ;
/* hat tip: "data _null_" on SAS-L */
data _null_;
/* using member syntax here */
infile inzip(LLCP2022XPT.xpt)
lrecl=256 recfm=F length=length eof=eof unbuf;
file xl lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
Also, if the file is located in the cloud or public then you can download it using proc https.
Thanks Reeza, But as i told i am very new, so i could understand, but also tried the 2nd part but rcvd error. I used your above code that is generating and LLCP2022.XPT with 0 byte. here is my file. please advise
A screenshot isn't helpful, you should include the log.
Here's a full example of the code. Make the changes to your code appropriately. If you have issues, include your LOG.
*path to the zip file; filename src zip "/home/fkhurshed/Demo2/P_DR2IFF.zip"; *path to where to save the xpt file; filename xl "/home/fkhurshed/Demo2/P_DR2IFF.xpt" ; *extract file from zip - P_DR2IFF.XPT in the code below is the name of the file in the zipped file that is to be extracted; data _null_; /* using member syntax here */ infile src(P_DR2IFF.XPT) lrecl=256 recfm=F length=length eof=eof unbuf; file xl lrecl=256 recfm=N; input; put _infile_ $varying256. length; return; eof: stop; run; *where to store the SAS dataset; libname projfile '/home/fkhurshed/Demo2/'; *XPT file (same as filename xl as above); libname xptfile xport '/home/fkhurshed/Demo2/P_DR2IFF.xpt' access=readonly; *extract the SAS dataset from the XPT file; proc copy inlib=xptfile outlib=projfile; run;
Here is the log, please check
Check this spelling:
"/home/u63672513/Mydata/LLCP2022XPT.zip"
It must be exactly how the path is named in the filesystem, particularly with regards to upper/lowercase. The UNIX system on which On Demand runs is case sensitive.
After uploading the zip file, right-click on it in the file navigation and copy the whole name from there.
Also make sure that the spelling of the xpt member in the zip archive is correct.
The code shown here does not agree with the name you showed in the picture you posted before.
The code is using:
infile src(LLCP2022.xpt)
But the name that I read from the picture you posed is:
LLCP2022.XPT
Can you see the difference?
To see what type of file your "xpt" file is read the first 80 bytes.
data _null_;
infile "/home/u63672513/Mydata/LLCP2022XPT.zip" zip
member='*' lrecl=80 recfm=f obs=1;
input;
list;
run;
If the first line looks like:
**COMPRESSED** **COMPRESSED** **COMPRESSED** **COMPRESSED** **COMPRESSED********
Then your "xpt" file is a CPORT file and you will need to use PROC CIMPORT to read it.
If the first line looks like:
HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000
then you have a version 5 XPORT file and you can use the XPORT libref engine to read it.
If the fist line looks like
HEADER RECORD*******LIBV8 HEADER RECORD!!!!!!!000000000000000000000000000000
Then you have a version 9 XPORT file you will have to use the %XPT2LOC() macro to read it.
I believe it's case sensitive and XPT needs to be capitalized in the statement.
infile src(LLCP2022.xpt) lrecl=256 recfm=F length=length eof=eof unbuf;
What kind of XPT file is it?
Is it a SAS V5 XPORT file (made with the XPORT libref engine)?
Is it a SAS V9 XPORT file (made with the autocall macro %LOC2XPT)?
Is it a CPORT file (made with PROC CPORT)?
You can use this macro to detect the filetype.
How about using BasePlus package and the %unzipArch() macro to get content of that zip?
filename SPFinit url "https://bit.ly/SPFinit";
%include SPFinit;
filename packages "/home/u63672513/packages"; /* create that directory*/
%installPackage(SPFinit BasePlus)
%loadPackage(BasePlus)
%unzipArch(
LLCP2022XPT.zip
, path = /home/u63672513/Mydata/
, target = /home/u63672513/Mydata/
, list=1
)
bart
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.