BookmarkSubscribeRSS Feed
aaditawhid
Calcite | Level 5

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

11 REPLIES 11
Reeza
Super User

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. 

 

https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in...

 

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.

aaditawhid
Calcite | Level 5

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

aaditawhid_0-1699650291318.png

 

 

Reeza
Super User

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;
aaditawhid
Calcite | Level 5
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69 *path to the zip file;
70 filename src zip "/home/u63672513/Mydata/LLCP2022XPT.zip";
71
72 *path to where to save the xpt file;
73 filename xl "/home/u63672513/Mydata/LLCP2022.xpt" ;
74
75 *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
75 ! extracted;
76 data _null_;
77 /* using member syntax here */
78 infile src(LLCP2022.xpt)
79 lrecl=256 recfm=F length=length eof=eof unbuf;
80 file xl lrecl=256 recfm=N;
81 input;
82 put _infile_ $varying256. length;
83 return;
84 eof:
85 stop;
86 run;
 
ERROR: Entry LLCP2022.xpt in zip file /home/u63672513/Mydata/LLCP2022XPT.zip does not exist.
ERROR: Physical file does not exist, LLCP2022.xpt.
NOTE: UNBUFFERED is the default with RECFM=N.
NOTE: The file XL is:
Filename=/home/u63672513/Mydata/LLCP2022.xpt,
Owner Name=u63672513,Group Name=oda,
Access Permission=-rw-r--r--,
Last Modified=11Nov2023:10:27:26
 
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 553.87k
OS Memory 19616.00k
Timestamp 11/11/2023 04:27:26 AM
Step Count 24 Switch Count 0
Page Faults 0
Page Reclaims 150
Page Swaps 0
Voluntary Context Switches 9
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
 
 
87
88 *where to store the SAS dataset;
89 libname projfile '/home/u63672513/Mydata';
NOTE: Libref PROJFILE refers to the same physical library as SASDATA1.
NOTE: Libref PROJFILE was successfully assigned as follows:
Engine: V9
Physical Name: /home/u63672513/Mydata
90
91 *XPT file (same as filename xl as above);
92 libname xptfile xport '/home/u63672513/Mydata/LLCP2022.xpt' access=readonly;
NOTE: Libref XPTFILE was successfully assigned as follows:
Engine: XPORT
Physical Name: /home/u63672513/Mydata/LLCP2022.xpt
93
94 *extract the SAS dataset from the XPT file;
95 proc copy inlib=xptfile outlib=projfile;
96 run;
 
NOTE: Input library XPTFILE is sequential.
WARNING: Input library XPTFILE is empty.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 589.40k
OS Memory 19876.00k
Timestamp 11/11/2023 04:27:26 AM
Step Count 25 Switch Count 0
Page Faults 0
Page Reclaims 107
Page Swaps 0
Voluntary Context Switches 2
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
 
97
98 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
108
Here is the log, please check
Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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?

Spoiler
Wrong case on the letters in the extension.
Tom
Super User Tom
Super User

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.

 

Reeza
Super User

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;
Tom
Super User Tom
Super User

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.

https://github.com/sasutils/macros/blob/master/xpttype.sas

aaditawhid
Calcite | Level 5
Hello Dear all, Very sorry, I am really new to SAS, I just need to get the XPT file from the zip file then i need it to convert in sas7bdat. But Due to file size (more then 1 gig) i can not import it from local PC
yabwon
Onyx | Level 15

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



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 11 replies
  • 2579 views
  • 0 likes
  • 5 in conversation