I know this has been answered before but I could not find the solution that works for me. The task seems to be easier, I just want to download a folder (named "my_data") containing all my data from SAS on demand to my pc locally. Does someone know an easy solution to this? I am trying this code but does not work (it keeps running forever):
filename indir '/home/u48749812/my_data';
filename out zip '/home/u48749812/my_data.zip';
data _null_;
length fname mname $256 ;
did=dopen('indir');
putlog did=;
do i=1 to dnum(did) ;
mname=dread(did,i);
if scan(mname,-1,'.')='sas7bdat' then do;
n+1;
putlog n= mname= ;
fname=catx('/',pathname('indir'),mname);
infile dummy filevar=fname end=eof;
file out memvar=mname;
do while (not eof);
input ;
put _infile_;
end;
end;
end;
did=dclose(did);
run;
Many thanks!
INFILE and SAS data sets are typically not used. INFILE and INPUT are expecting text files.
I suggest a test getting rid of all the attempt to read from a directory and hard code the name of one data set and see if you can write it out the way you have attempted and see what happens. (Or did you try that earlier?)
I would suggest looking into Proc Cport to create a transport file from all the datasets in a library. One advantage of transport files that when read into another system using Proc Cimport the OS version doesn't matter as it does a conversion to a native to the new host SAS version.
Try
Hope this helps
Do you have SAS datasets in subdirectories?
If not then just use PROC CPORT to make one file with all of the datasets.
libname mydata '/home/u48749812/my_data/';
filename out zip '/home/u48749812/my_data.zip' memname='my_data.cport';
proc cport lib=mydata file=out mt=data;
run;
If yes then you will need to process each directory with SAS datasets separately.
libname mydata '/home/u48749812/my_data/';
filename out zip '/home/u48749812/my_data.zip' memname='my_data.cport';
proc cport lib=mydata file=out mt=data;
run;
libname mydata '/home/u48749812/other_data/';
filename out zip '/home/u48749812/my_data.zip' memname='other_data.cport';
proc cport lib=mydata file=out mt=data;
run;
...
Note your program is reading SAS datasets as if they are text files. Even if it was successful in writing to the ZIP file the files written would be useless. You should read/write them as BINARY data instead.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.