BookmarkSubscribeRSS Feed
Obsidian | Level 7

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/';
data _null_;
  length fname mname $256 ;
  putlog did=;
  do i=1 to dnum(did) ;
     if scan(mname,-1,'.')='sas7bdat' then do;
       putlog n= mname= ;
       infile dummy filevar=fname end=eof;
       file out memvar=mname;
       do while (not eof);
         input ;
         put _infile_;


Many thanks!

Super User

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.


Rhodochrosite | Level 12



  1. Using the ODS PACKAGE to create a zip file (Creating ZIP Files with ODS) of all your files, and save it in your Home directory ('/home/u48749812/')
  2. Select the generated zip file then use SAS Studio's Download tool Studio_tools.PNGto download it to you local PC


Hope this helps

Super User Tom
Super User

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/' memname='my_data.cport';
proc cport lib=mydata file=out mt=data;

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/' memname='my_data.cport';
proc cport lib=mydata file=out mt=data;

libname mydata '/home/u48749812/other_data/';
filename out zip '/home/u48749812/' memname='other_data.cport';
proc cport lib=mydata file=out mt=data;


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.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4 in conversation