In SAS® Drug Development, users typically take local directories containing one or more files, ZIP files, and then upload and expand the ZIP file into a Repository or Workspace folder using the SAS® Drug Development API Macros. The sample program in the Download tab contains code demonstrating doing this using the ODS PACKAGE functionality built into SAS® for Microsoft Windows. It does not require additional software like WinZip Command Line add-in.
The sample program does the following:
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
SAMPLE code for zipping a folder to be uploaded and expanded into SAS® Drug Development.
/*----------------------------------------------------------------------
* SAMPLE code for zipping a folder to be uploaded and expanded into
* SAS Drug Development.
*
* This sample code was written for use in a Windows environment. You must
* modify this sample code to run in other environments
*
* Macro parameters:
* localFilePath: The folder that will be zipped up and uploaded/expanded into SDD.
* This can be a local path or a network path.
* The path MUST end with a slash ("\").
*
* zipFileName: The file name of the zip file to be uploaded.
*
* zipFilePath The path that the zip file will be saved.
* This can be a local path or a network path.
* The path MUST end with a slash ("\").
*
* unzipPath: The path in SDD that the zip file will be uploaded and expanded.
* The path MUST already exist in SDD.
* The path MUST NOT end with a slash.
*
* Revised: 31MAR2016
*
* SAS INSTITUTE INC. IS PROVIDING YOU WITH THE COMPUTER SOFTWARE CODE
* INCLUDED WITH THIS AGREEMENT ("CODE") ON AN "AS IS" BASIS, AND
* AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS HEREOF. BY USING
* THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR
* OWN RISK. SAS INSTITUTE INC. MAKES NO REPRESENTATION OR WARRANTY,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND
* TITLE, WITH RESPECT TO THE CODE.
*
* The Code is intended to be used solely as part of a product
* ("Software") you currently have licensed from SAS Institute Inc. or
* one of its subsidiaries or authorized agents ("SAS"). The Code is
* designed to either correct an error in the Software or to add
* functionality to the Software, but has not necessarily been tested.
* Accordingly, SAS makes no representation or warranty that the Code
* will operate error-free. SAS is under no obligation to maintain or
* support the Code.
*
* Neither SAS nor its licensors shall be liable to you or any third
* party for any general, special, direct, indirect, consequential,
* incidental or other damages whatsoever arising out of or related to
* your use or inability to use the Code, even if SAS has been advised of
* the possibility of such damages.
*
* Except as otherwise provided above, the Code is governed by the same
* agreement that governs the Software. If you do not have an existing
* agreement with SAS governing the Software, you may not use the Code.
*
*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
* Step 1.
* Set macro variables for the SDD instance and user credentials
*
* These credentials can be incorporated as parameters in the macro
* below, if desired.
/*----------------------------------------------------------------------*/
%let sddurl=%str();
%let sddusr=%str();
%let sddpw=%nrbquote();
%macro zipUploadAndExpand( localFilePath, zipFileName, zipFilePath, unzipPath );
/*----------------------------------------------------------------------
* Step 2.
* Get file of all files within a directory and all subdirectories.
/*----------------------------------------------------------------------*/
filename filelist pipe "dir /b /s /A:-D &localFilePath";
/*----------------------------------------------------------------------
* Step 3.
* Create a data set with all files and what their path within
* the package will be.
/*----------------------------------------------------------------------*/
data filesInFolder(drop=pathLength);
/* Read in the file fileList */
infile filelist truncover;
input filename $100.;
/* Get the length of the path of the subdirectory for the current file. */
pathLength = length(trim(filename)) - find(reverse(trim(filename)),'\','t',1) - length("&localFilePath") + 1;
/* Get the path of the subdirectory for the current file */
/* Ex: localFilePath of C:\Project\Subdirectory1 would equate to \Subdirectory1 */
folderPath = SubStr(trim(filename),length("&localFilePath"),pathLength);
/* Replace back slashes with forward slashes */
folderPath = tranwrd(folderPath, "\", "/");
/* If pathLength is 0, the current file is at the root of the localFilePath. */
if pathLength = 0 then
folderPath = "/";
run;
/*----------------------------------------------------------------------
* Step 4.
* Create macro variables needed to add files to the package.
/*----------------------------------------------------------------------*/
/* Loop through every file in the filesInFolder data set. */
data _NULL_;
set filesInFolder;
/* Create macro variable for the filename to be added to the package. */
call symput(compress('file' || _n_),filename);
/* Create a corresponding macro variable for the path that the file should be stored within the package. */
call symput(compress('folder' || _n_),folderPath);
/* Create a macro variable with the total number of files to be added to the package. */
call symput('total',_n_);
run;
/*----------------------------------------------------------------------
* Step 5.
* Create a package/zip file with all the files in the folder/subfolders
/*----------------------------------------------------------------------*/
/* Open the ods packages with the NOPF option set to not include PackageMetaData file. */
ods package open nopf;
/* Add each file to the package at the appropriate path within the zip file. */
%do i = 1 %to &total.;
ods package add file="%trim(&&file&i.)" path="&&folder&i.";
%end;
/* Publish the package with the appropriate properties */
ods package publish archive properties(archive_name="&zipFileName" archive_path="%trim(&zipFilePath)");
/* Close the ods package */
ods package close;
/*----------------------------------------------------------------------
* Step 6.
* Login to SDD, upload and expand the zip file, and log out.
/*----------------------------------------------------------------------*/
/* Login to establish a new SAS Session */
%sasdrugdev_login(sdd_url=&sddurl, sdd_userid=&sddusr, sdd_password=&sddpw);
/* Upload and expand the zip file to specified location in SDD */
%sasdrugdev_uploadandexpand(local_path=&zipFilePath&zipFileName, sdd_path=&unzipPath., sdd_versioning=, sdd_version=, sdd_comment=);
/* Logout of SAS Session */
%sasdrugdev_logout;
/*----------------------------------------------------------------------*/
%mend zipUploadAndExpand;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
For viewing in text editor click here:
To download a ZIP withe same program click here:
Type: | Sample |
Date Modified: | 2016-04-01 11:36:04 |
Date Created: | 2016-04-01 10:40:40 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | SAS Drug Development | Linux for x64 | 4.5 | 9.4 TS1M2 |