BookmarkSubscribeRSS Feed
marta25
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/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!

3 REPLIES 3
ballardw
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.

 

AhmedAl_Attar
Rhodochrosite | Level 12

@marta25 

Try

  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

Tom
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/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.

sas-innovate-2024.png

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
  • 2281 views
  • 3 likes
  • 4 in conversation