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;
To download a directory of SAS files using SAS Studio or SAS on Demand, you can use the following steps:
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.
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;
To zip all datasets from test3 library and store the zip file in test4 library just execute:
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:
As a result you will get all elements from the test3.zip extracted into the test4 library location.
PS How to get BasePlus?
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 */
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.