Hello,
here,s my sas code:
%let work=%sysfunc(pathname(work));
%let year=2024;
%let VAR_MOIS=nov;
%let path=/.../sas&year./gc;
%let fname=pa.pxp4xax.sep4tuac.mo1a;
%let fextension=dat1;
%PUT "&path./&fname";
%put "&path./&fname..&VAR_MOIS.&year..dat1";
%put "&fname.";
filename oscmd pipe "uncompress -c &path./&fname..&VAR_MOIS.&year..zip > &work./&fname..&VAR_MOIS.&year..&fextension 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
log file:
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
28
29 %let work=%sysfunc(pathname(work));
30 %let year=2024;
31 %let VAR_MOIS=nov;
32 %let path=/.../sasdata/sas&year./gc;
33 %let fname=pa.pxp4xax.sep4tuac.mo1a;
34 %let fextension=dat1;
35 %PUT "&path./&fname";
"/.../sasdata/sas2024/gc/pa.pxp4xax.sep4tuac.mo1a"
36 %put "&path./&fname..&VAR_MOIS.&year..dat1";
"/.../sasdata/sas2024/gc/pa.pxp4xax.sep4tuac.mo1a.nov2024.dat1"
37 %put "&fname.";
"pa.pxp4xax.sep4tuac.mo1a"
38
39 filename oscmd pipe "uncompress -c &path./&fname..&VAR_MOIS.&year..zip > &work./&fname..&VAR_MOIS.&year..&fextension
39 ! 2>&1";
40
41 data _null_;
42 infile oscmd;
43 input;
44 put _infile_;
45 run;
NOTE: The infile OSCMD is:
Pipe command="uncompress -c /dwh_actuariat/sasdata/sas2024/gc/pa.pxp4xax.sep4tuac.mo1a.nov2024.zip >
/saswork2/ua_bicoe/SAS_work05F100009018_stha8p08j/SAS_workEF3B00009018_stha8p08j/pa.pxp4xax.sep4tuac.mo1a.nov2024.dat1 2>&1"
NOTE: 0 records were read from the infile OSCMD.
NOTE: DATA statement used (Total process time):
2 The SAS System 09:59 Tuesday, December 10, 2024
real time 0.00 seconds
cpu time 0.00 seconds
46
I would suggest looking at the FILENAME ZIP statement instead of a pipe command.
From the online help:
filename foo ZIP 'U:\directory1\testzip.zip' member="test1.txt" ; data _null_; infile foo; input a $80.; run;
Note that this assumes you know the member of the file in the zip you want, in this case test1.txt.
May need the TERMSTR option as well.
XCMD needed for pipes is often turned off by admins in server installs, so your pipe may not have executed at all. Plus it looks like you directed the output of the uncompress to a file instead of standard output that the PIPE would use.
uncompress is not the OS command to deal with ZIP files. If you have a ZIP file the OS command you want to use is unzip (or perhaps 7z or some other command that understands archive files).
compress/uncompress is a tool that only handles single files. Typically it appends .Z to the name of the original file when it makes the compressed version. It is more like gzip in that sense. GZIP also only compresses single files. Gzipped files typically have .gz appended to their name.
ZIP files can have multiple files inside of them.
So did you check whether that command worked or not? I sounds like it did work since you did not read in any error messages when you ran it. (I doubt it would work unless for some reason you used compress to create a compressed version of a file and named it with .zip as the extension even though it was not a ZIP archive.)
Try reading in the first line from the file it wrote.
data _null_;
input """&work./&fname..&VAR_MOIS.&year..&fextension""" obs=1;
input;
list;
run;
Or trying running the ls command to see if it wrote the file.
data _null_;
input "ls -l ""&work./&fname..&VAR_MOIS.&year..&fextension""" pipe ;
input;
list;
run;
And if you want to do what your message says remove the > from the OS command and use a data step that actually reads the file. For example if that was a compressed CSV file you might use something like:
filename oscmd pipe "uncompress -c &path./&fname..&VAR_MOIS.&year..zip 2>&1";
data want;
infile oscmd firstobs=2 dsd truncover;
input var1 var2 :$30 ;
run;
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.