1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 /************************************************************* 70 Note: This program will not run properly on z/OS. 71 Only Windows, Linux and UNIX are supported. 72 Values for PATH are CASE SENSITIVE. 73 *************************************************************/ 74 %let path=/home/&sysuserid/EPG194; 75 76 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 77 WARNING: DO NOT ALTER CODE BELOW THIS LINE IN ANY WAY 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 79 80 /* Make sure path consistently uses forward slashes */ 81 %let course=epg194; 82 %let path=%qsysfunc(translate(%superq(path),/,\)); 83 %let original_path=%superq(path); 84 85 /*options nomprint nosymbolgen nonotes nosource dlcreatedir;*/ 86 options mprint symbolgen notes source; 87 88 %macro unpack(unzip /* Full path pointing to where to create the EPG194 data */ 89 ,zipfilename /* ZIP File name (used to download with PROC HTTP) */ 90 ,coursecode /* Represents the top level folder of the ZIP file; can be used for conditional logic */); 91 92 %local rc fid fileref fnum memname big_zip big_zip_found data_zip data_zip_found url; 93 %global cre8data_success path; 94 %let cre8data_success=0; 95 %let url=%str(http://dl.liveweb.sas.com/eldata/pg194_oda_linkedin.zip); 96 97 98 /* Is the path specified valid? */ 99 %let fileref=unzip; 100 %let rc=%sysfunc(filename(fileref,%superq(unzip))); 101 %let path_found=%sysfunc(fileref(unzip)); 102 %if &path_found ne 0 %then %do; 103 %put %sysfunc(sysmsg()); 104 %put ERROR: ************************************************************; 105 %put ERROR- Path specified for data files (%superq(unzip)) is not valid.; 106 %put ERROR- Remember: PATH values in UNIX and LINUX are case sensitive. ; 107 %put ERROR- ************************************************************; 108 %let rc=%sysfunc(filename(fileref)); 109 %return; 110 %end; 111 112 /* Get just the filename of the zipfile, not the .ZIP extension */ 113 %if %qscan(%qupcase(%superq(zipfilename)),2,.) = %str(ZIP) %then %do; 114 %let zipfilename = %qscan(%superq(zipfilename),1,.) ; 115 %end; 116 117 /* Test for the presence of the main ZIP file in the path */ 118 %let fileref=bigzip; 119 %let rc=%sysfunc(filename(fileref,%superq(unzip)/%superq(zipfilename).zip,zip)); 120 %let big_zip_found=%sysfunc(fileref(bigzip)); 121 %if &big_zip_found ne 0 %then %do; 122 %put NOTE: %superq(zipfilename).zip not found in %superq(unzip).; 123 %put NOTE- Attempting to download the ZIP file from the internet.; 124 filename BigZip "%superq(unzip)/%superq(zipfilename).zip"; 125 proc http 126 url="%superq(url)" 127 out=BigZip method="get"; 128 ; 129 130 run; 131 132 %let big_zip_found=%sysfunc(fileref(bigzip)); 133 %if &big_zip_found ne 0 %then %do; 134 %put ERROR: *************************************************************; 135 %put ERROR- Attempt to download %superq(zipfilename).zip unsuccessful.; 136 %put ERROR- *************************************************************; 137 filename BigZip; 138 %return; 139 %end; 140 %end; 141 142 options dlcreatedir; 143 libname xx "%superq(path)"; 144 libname xx clear; 145 146 /* Read the "members" (files) from the ZIP file */ 147 /* Create the data folder structure and get a list of files in macro variables */ 148 filename BigZip zip "%superq(unzip)/%superq(zipfilename).zip"; 149 data _null_; 150 length memname pathname $500; 151 fid=dopen("bigzip"); 152 if fid=0 then stop; 153 memcount=dnum(fid); 154 do i=1 to memcount; 155 memname=dread(fid,i); 156 /* Create and empty folder for each folder in the ZIP file */ 157 /* check for trailing / in folder name */ 158 isFolder = (first(reverse(trim(memname)))='/'); 159 /* if isfolder then put memname= isfolder=;*/ 160 if isfolder then do; 161 pathname=cats("&path/",substr(memname,1,length(memname)-1)); 162 put "NOTE: Creating path " pathname; 163 rc1=libname('xx',pathname); 164 rc2=libname('xx'); 165 end; 166 else do; 167 filecount+1; 168 call symputx(cats('out',filecount),memname,'L'); 169 end; 170 end; 171 rc=dclose(fid); 172 call symputx('filecount',filecount,'L'); 173 run; 174 175 %do i=1 %to &filecount; 176 filename out "%superq(unzip)/%superq(out&i)"; 177 data _null_; 178 infile bigzip(%superq(out&i)) 179 lrecl=256 recfm=F length=length eof=eof unbuf; 180 file out lrecl=256 recfm=N; 181 input; 182 put _infile_ $varying256. length; 183 return; 184 eof: 185 stop; 186 run; 187 %end; 188 189 filename bigzip; 190 filename out; 191 filename unzip; 192 193 %let setup=%superq(unzip)/setup.sas; 194 %let cre8data_ready=%sysfunc(fileexist(%superq(setup))); 195 196 %if not &cre8data_ready %then %do; 197 %put; 198 %put ERROR: ********************************************************************; 199 %put ERROR- After unzipping %superq(zipfilename).zip, setup.sas program not found ; 200 %put ERROR- in folder %superq(unzip).; 201 %put ERROR- Download and unzip %superq(zipfilename)_data.zip manually, then; 202 %put ERROR- run cre8data.sas again.; 203 %put ERROR- ********************************************************************; 204 %put; 205 %end; 206 207 %let path=%superq(unzip)/data; 208 209 %include "%superq(setup)"; 210 211 %mend unpack; 212 213 %unpack(%superq(path),epg194.zip,epg194) SYMBOLGEN: Macro variable PATH_FOUND resolves to 0 SYMBOLGEN: Macro variable BIG_ZIP_FOUND resolves to -20006 NOTE: epg194.zip not found in /home/rickysaldanha0/EPG194. Attempting to download the ZIP file from the internet. MPRINT(UNPACK): filename BigZip "/home/rickysaldanha0/EPG194/epg194.zip"; MPRINT(UNPACK): proc http url="http://dl.liveweb.sas.com/eldata/pg194_oda_linkedin.zip" out=BigZip method="get"; MPRINT(UNPACK): ; MPRINT(UNPACK): run; NOTE: 404 Not Found NOTE: PROCEDURE HTTP used (Total process time): real time 1.67 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 311.25k OS Memory 19360.00k Timestamp 01/03/2023 12:52:54 PM Step Count 24 Switch Count 3 Page Faults 0 Page Reclaims 210 Page Swaps 0 Voluntary Context Switches 21 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 SYMBOLGEN: Macro variable BIG_ZIP_FOUND resolves to 0 MPRINT(UNPACK): options dlcreatedir; MPRINT(UNPACK): libname xx "/home/rickysaldanha0/EPG194"; NOTE: Libref XX was successfully assigned as follows: Engine: V9 Physical Name: /home/rickysaldanha0/EPG194 MPRINT(UNPACK): libname xx clear; NOTE: Libref XX has been deassigned. MPRINT(UNPACK): filename BigZip zip "/home/rickysaldanha0/EPG194/epg194.zip"; MPRINT(UNPACK): data _null_; MPRINT(UNPACK): length memname pathname $500; MPRINT(UNPACK): fid=dopen("bigzip"); MPRINT(UNPACK): if fid=0 then stop; MPRINT(UNPACK): memcount=dnum(fid); MPRINT(UNPACK): do i=1 to memcount; MPRINT(UNPACK): memname=dread(fid,i); MPRINT(UNPACK): isFolder = (first(reverse(trim(memname)))='/'); MPRINT(UNPACK): if isfolder then do; SYMBOLGEN: Macro variable PATH resolves to /home/rickysaldanha0/EPG194 SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. MPRINT(UNPACK): pathname=cats("/home/rickysaldanha0/EPG194/",substr(memname,1,length(memname)-1)); MPRINT(UNPACK): put "NOTE: Creating path " pathname; MPRINT(UNPACK): rc1=libname('xx',pathname); MPRINT(UNPACK): rc2=libname('xx'); MPRINT(UNPACK): end; MPRINT(UNPACK): else do; MPRINT(UNPACK): filecount+1; MPRINT(UNPACK): call symputx(cats('out',filecount),memname,'L'); MPRINT(UNPACK): end; MPRINT(UNPACK): end; MPRINT(UNPACK): rc=dclose(fid); MPRINT(UNPACK): call symputx('filecount',filecount,'L'); MPRINT(UNPACK): run; NOTE: DATA statement used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 557.53k OS Memory 19872.00k Timestamp 01/03/2023 12:52:54 PM Step Count 25 Switch Count 0 Page Faults 0 Page Reclaims 121 Page Swaps 0 Voluntary Context Switches 5 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 WARNING: Apparent symbolic reference FILECOUNT not resolved. ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &filecount ERROR: The %TO value of the %DO I loop is invalid. ERROR: The macro UNPACK will stop executing. SYMBOLGEN: Macro variable SYSUSERID resolves to rickysaldanha0 214 215 /* added to set &path for elearning */ 216 %let path=/home/&sysuserid/EPG194/data; 217 218 options mprint notes source; 219 220 221 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; SYMBOLGEN: Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE; 231