*---Revised 6/28/2016 9:50:05 AM to handle _inmetadata flag---; data _null_; set contents2(keep=Filename Description _inmetadata); file "&dir./Contents" lrecl=2000; length _line $80 line $80; length _chunk $2000 d_chunk $2000; retain _chunksize 56 _chunkpos 0; retain _lf '0A'x; if _n_ eq 1 then do; line = "Contents: &dir"; * Generate revision date and time, as the description will be updated as indicated in specs ; _date = date(); _time = time(); put line @63 "Rev: " _date date7. '-' _time hhmm5.; line = repeat('=', 79); put line; put; end; * ; * trim Filename, add two mandatory dots, then pad Filename with dots ; * to make up for up to 25 chars and put Filename with a pending sign for ; * first line of description ; * ; Filename = trim(Filename) || '..'; if length(trim(Filename)) < 25 then do; Filename = trim(Filename) || repeat('.', 25 - length(Filename) - 1); end; _first_line = 1; Description = compbl(Description); if _inmetadata then Description=trim(Description)|| '0A'x ||'(See metadata)'; _l = length(Description); * ; * Split Description into _chunksize chunks, but consider that it may ; * contain LF. When it has LF in the chunk, it delivers the part before LF ; * then starts a new chunk after the LF ; * ; if _l = 1 then do; put Filename ' '; end; if _l > 1 then do; _chunk = substr(Description, 1); _len = length(_chunk); do while (_len > 1); d_chunk = substr(_chunk, 1, min(length(_chunk), _chunksize)); _lfpos = index(d_chunk, '0A'x); if _lfpos > 0 then do; d_chunk = substr(d_chunk, 1, _lfpos - 1); _chunkpos = _lfpos + 1; end; else do; if length(_chunk) > length(d_chunk) then do; r_chunk = reverse(d_chunk); _word = scan(r_chunk, 1); d_chunk = substr(d_chunk, 1, length(d_chunk) - length(_word) - 1); end; _chunkpos = length(d_chunk) + 1; end; if _first_line = 1 then do; _first_line = 0; _line = trim(Filename) || d_chunk; put _line; end; else do; put @26 d_chunk; end; _chunk = substr(_chunk, _chunkpos); _len = length(_chunk); end; end; *; * Finally, put an empty line to indicate end of file information section ; *; put; run;