****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: createlibref.sas
* Created (mm/dd/yyyy): 11/28/2017
*
*--------------------------------------------------------------------------------------------------
* PURPOSE: This macro creates concatenated libref from a list of DPs and a file path,
* automatically defaults to most recent version, and checks for the existence of each folder path
*
* Program inputs:
* -
*
* Program outputs:
* -
*
* PARAMETERS:
* - dplist: list of DPs separated by a space
* - dpinfofile: file containing list of DPs and optional path
* - dataroot: location of /data folder in the standard structure /data/[version]/[dp]/msoc/
* - signaturefile: signature file from which to extract DP metadata
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro createlibref(dplist=,
dpinfofile = ,
dataroot = ,
signaturefile = );
**********************************************************
macro %dynamiclibref automatically creates libnames for
each DP based on K:/Sentinel folder structure
*********************************************************;
%macro dynamiclibref(dp_list=);
filename root "&dataroot.";
/*Retrieve each version*/
data files_and_folders;
length name $50;
drop rc did i;
did=dopen("root");
if did > 0 then do;
do i=1 to dnum(did);
name=upcase(dread(did,i));
output;
end;
rc=dclose(did);
end;
else put 'Could not open directory';
run;
/*Defensive coding*/
proc sort data=files_and_folders;
by descending name;
run;
/*Put name of versions into macro variable*/
proc sql noprint;
select lowcase(name) into: versions separated by ' '
from files_and_folders
where substr(upcase(name),1,1) = 'V' or substr(upcase(name),1,1) = 'B';
quit;
%put &versions;
/*For each DP, confirm the existence of the directory. Only include directories that exist in the final concatenated libname*/
%let dp_list = %lowcase(&dp_list);
%let DpCnt = %sysfunc(Countw(&dp_list)); /*Number of DPs to loop*/
%let VerCnt = %sysfunc(Countw(&versions)); /*Number of versions to loop*/
%do a = 1 %to &DpCnt;
%let DPSITEID = %scan(&dp_list,&a); /*Current DP*/
/*reset in_version counter*/
%let in_version = ;
%do b = 1 %to &VerCnt;
%let CurrVer = %scan(&versions,&b); /*Current version*/
/*does directory exist for current version?*/
%let dir = &dataroot./&CurrVer./&DPSITEID./msoc/;
%let rc = %sysfunc(filename(fileref,&dir)) ;
%if %sysfunc(fexist(&fileref)) %then %let in_version = &in_version &CurrVer;