BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

Use MEMVAR= option, not MEMBER= option.

 

If that doesn't work then try using DOPEN() DNUM(), DREAD() to get the list of files instead.

filename indir '/home/u.../sasmacs2';
filename out zip '/home/u.../sasmacs2.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,'.')='sas' 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;
MaryA_Marion
Lapis Lazuli | Level 10

The suggestion Use MEMVAR= option, not MEMBER= option worked just fine. Thank you. MM

ShelleySessoms
Community Manager

Great suggestion, @ChrisNZ. I have pinned this for all users. Thanks for thinking of efficient ways to help our members!

kxnjqdil
Calcite | Level 5

Just Try providing the full path in to a folder where you can write away!

MMSTAT
Calcite | Level 5

Part I
filename in '/home/u50158717/FILE(HOME)';
filename out zip '/home/u50158717/FILE.HOME.zip';
data _null_;
length fname mname $256 ;
infile in('*') filename=fname ;
input;
mname = scan(fname,-1,'/\');
file out MEMVAR=mname;
put _infile_;
run; quit;

 

filename in 'path to files'; precisely what is this?
I have filename in '/home/u50158717/FILE(HOME)';
It is not working. Part II is working just fine.

 

Part II
filename in '/home/u50158717/macros';
filename out zip '/home/u50158717/macros.zip';
data _null_;
length fname mname $256 ;
infile in('*') filename=fname ;
input;
mname = scan(fname,-1,'/\');
file out MEMVAR=mname;
put _infile_;
run; quit;

 

Tom
Super User Tom
Super User

You actually have a directory named FILE(HOME) ?  With all capital letters and parentheses?

 

Note that ( and ) are normally special characters to Unix so using them as part of a filename could be a problem.    Can you rename the directory first to something more normal?

 

You might try adding escape characters for the (). Not sure if that really works however.

filename in '/home/u50158717/FILE\(HOME\)';

You might try adding quotes around the whole name (inside the quotes needed for SAS to see a character string).

filename in '"/home/u50158717/FILE(HOME)"';

So it sounds like you actually do you have directory named macros.

 

Not sure where you saw something saying you should use 

filename in '/home/u50158717/FILE(HOME)';

Perhaps you are just confused by the SAS notation of how to reference a file within a directory as it is done in the INFILE statement in your code:

infile in('*') filename=fname ;

In that line IN is the name of the FILEREF that was defined previous with the FILENAME statement to point to the directory.  And the stuff inside the parentheses is the name of the individual file from that directory to read.  In this case it is using the * wildcard character to read ALL of the files.

webart999ARM
Quartz | Level 8

To download a directory of SAS files using SAS Studio or SAS on Demand, you can use the following steps:

 

  1. Open SAS Studio or SAS on Demand in your web browser.
  2. Navigate to the directory that contains the SAS files you want to download.
  3. Select the SAS files you want to download by clicking on the checkbox next to each file.
  4. Click on the "Download" button in the toolbar at the top of the page.
  5. In the "Download" window that appears, select the "Zip" option and click on the "Download" button.
  6. The zip file containing the SAS files will be downloaded to your computer.

Alternatively, you can use the "zip" command in SAS to create a zip file containing the SAS files. To do this, you will need to use the following code:

 

filename myfiles pipe "zip -r - myfiles.zip *.sas";
data null;
infile myfiles recfm=f lrecl=32767;
input;
file myfiles;
put infile;
run;

Replace "myfiles" with the name of the directory that contains the SAS files you want to download. This code will create a zip file called "myfiles.zip" that contains all the SAS files in the specified directory. You can then download the zip file to your computer using the "Download" button in SAS Studio or SAS on Demand.

yabwon
Onyx | Level 15

Hey All,

 

The solution is here for *.sas files but sometimes there is a need for zipping a library of SAS datasets. I thought I share my solution for such task.

The BasePlus package contains two macros dedicated to zipping and unzipping a library of datasets.

 

How to get basePlus package? I will write below, for now assume we already have it installed and loaded into our SAS session.

 

The zipping macro %zipLibrary() allows to zip all data sets (v7, v8, or v9 with indexes) from SAS library into one zip file:

Lets generate some example data:

 

options dlcreatedir;
  libname test1 "%workpath()/test1";
  libname test2 "%workpath()/test2";
  libname test3 (test1 test2);
  libname test4 "%workpath()/test4";
options nodlcreatedir;

%put %libPath(test3);
%put %libPath(test4);

data 
  test1.A(index=(model)) 
  test1.B(where=(Origin="Asia")) 
  test2.C 
  test2.D(where=(Origin NE "Asia") index=(model make io=(invoice origin))) 
;
  set sashelp.cars;
run;

data test1.B2 / view=test1.B2;
  set test1.B;
  output;
  output;
run;

 

(the %libPath() and %workpath() are utility macros in BasePlus package).

 

To zip all datasets from test3 library and store the zip file in test4 library just execute:

%zipLibrary(test3, libOut=test4)

as a result you will get test3.zip file inside the test4 library.

 

When the zip is ready you can just copy it whenever you want and unzip it by hand (with 7zip for example) or you can use the %unzipLibrary() macro:

 

%unzipLibrary(%libPath(test4), zip=test3)

As a result you will get all elements from the test3.zip extracted into the test4 library location.

 

 

Bart

 

PS How to get BasePlus?

To work with SAS Packages like BasePlus or others you will need SAS Packages Framework.

 

Lets assume your SAS session has access to the internet (if not look below).

1) Create a directory where you want to store SPF and packages, for example let it be: "/home/myuserid/SASpackages" under Linux or "C:\Users\myuserid\SASpackages" under Windows.

2) Run the following code only one time to get the SPF:

 

filename packages "/home/myuserid/SASpackages"; /* setup directory for packages */
filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
%include SPFinit; /* enable the framework */

%installPackage(SPFinit) /* install SPF */
%installPackage(BasePlus) /* install BasePlus */

(installation of other packages goes the same way - by installPackage macro).

 

 

3) From now on, in this and any new SAS session, to enable SPF and BasePlus just run:

filename packages "/home/myuserid/SASpackages"; /* setup directory for packages */
%include packages(SPFinit.sas); /* enable the framework */

%loadPackage(BasePlus)    /* load the package content into the SAS session */

4) Enjoy 

 

PS2

No access to the internet on your machine? No problem! Instead step number 2 go here and manually download SPFinit.sas file. Then go to here and download baseplus.zip file. Store them in the directory from step 1 and proceed to step 3.

 

 

 

 

 

 

 

 

 

 

 

 

 

_______________
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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 23 replies
  • 19280 views
  • 17 likes
  • 10 in conversation