- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is the log, please check
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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