-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathOCR - Document Analysis - Execute Batch OCR Process.step
1 lines (1 loc) · 21.1 KB
/
OCR - Document Analysis - Execute Batch OCR Process.step
1
{"creationTimeStamp":"2024-12-05T14:47:33.375Z","modifiedTimeStamp":"2024-12-05T14:48:07.025Z","createdBy":"winado","modifiedBy":"winado","name":"OCR - Document Analysis - Execute Batch OCR Process.step","displayName":"OCR - Document Analysis - Execute Batch OCR Process.step","localDisplayName":"OCR - Document Analysis - Execute Batch OCR Process.step","description":"The OCR - Document Analysis - Execute Batch OCR Process custom steps enables an easy integration with the SAS Document Analysis (SDA) model, to run a full batch job, without the need to write any code.","localDescription":"The OCR - Document Analysis - Execute Batch OCR Process custom steps enables an easy integration with the SAS Document Analysis (SDA) model, to run a full batch job, without the need to write any code.","properties":{},"links":[{"method":"GET","rel":"self","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","type":"application/vnd.sas.data.flow.step"},{"method":"GET","rel":"alternate","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","type":"application/vnd.sas.data.flow.step.summary"},{"method":"GET","rel":"up","href":"/dataFlows/steps","uri":"/dataFlows/steps","type":"application/vnd.sas.collection","itemType":"application/vnd.sas.data.flow.step.summary"},{"method":"PUT","rel":"update","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","type":"application/vnd.sas.data.flow.step","responseType":"application/vnd.sas.data.flow.step"},{"method":"DELETE","rel":"delete","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb"},{"method":"POST","rel":"copy","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb/copy","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb/copy","responseType":"application/vnd.sas.data.flow.step"},{"method":"GET","rel":"transferExport","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","responseType":"application/vnd.sas.transfer.object"},{"method":"PUT","rel":"transferImportUpdate","href":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","uri":"/dataFlows/steps/98d5bf61-ed64-405e-bdbe-881a25f62dfb","type":"application/vnd.sas.transfer.object","responseType":"application/vnd.sas.summary"}],"metadataVersion":0.0,"version":2,"type":"code","flowMetadata":{"inputPorts":[],"outputPorts":[]},"ui":"{\n\t\"showPageContentOnly\": true,\n\t\"pages\": [\n\t\t{\n\t\t\t\"id\": \"pageOptions\",\n\t\t\t\"type\": \"page\",\n\t\t\t\"label\": \"Options\",\n\t\t\t\"children\": [\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_esb_source_data_directory_txt\",\n\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\"text\": \"SAS Studio Custom Step for executing the SAS Document Analysis OCR batch process. At a minimum, users must specify a folder containing files to be processed, the OCR engine to use and the SAS launcher context ID to execute against.\\n\\nThe source directory should contain files of the following types in order to be processed and should be located on the server file sysem (not in SAS Content): [PDF, PNG, JPG, JPEG, TIF, TIFF, BMP, ZIP]\",\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_sda_source_data_directory\",\n\t\t\t\t\t\"type\": \"path\",\n\t\t\t\t\t\"label\": \"Select directory containing source files to process:\",\n\t\t\t\t\t\"pathtype\": \"folder\",\n\t\t\t\t\t\"placeholder\": \"Select directory containing source files to process\",\n\t\t\t\t\t\"required\": true,\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_sda_ocr_engine\",\n\t\t\t\t\t\"type\": \"dropdown\",\n\t\t\t\t\t\"label\": \"Select cloud OCR engine:\",\n\t\t\t\t\t\"items\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"ms\",\n\t\t\t\t\t\t\t\"label\": \"Microsoft OCR\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"aws\",\n\t\t\t\t\t\t\t\"label\": \"AWS Textract\"\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t\"required\": true,\n\t\t\t\t\t\"placeholder\": \"Select cloud OCR engine\",\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_sda_launcher_context_id\",\n\t\t\t\t\t\"type\": \"textfield\",\n\t\t\t\t\t\"label\": \"Enter SAS launcher context ID:\",\n\t\t\t\t\t\"placeholder\": \"ex. b7be2e5f-a65a-4659-8e4e-84d833b2bcc5\",\n\t\t\t\t\t\"required\": true,\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_esb_launcher_context_id_txt\",\n\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\"text\": \"To get the SAS launcher context ID for the SDA launcher context please speak with your SAS Viya administrator that deployed SDA in your environment.\",\n\t\t\t\t\t\"visible\": \"\",\n\t\t\t\t\t\"indent\": 0\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_sda_log_level\",\n\t\t\t\t\t\"type\": \"dropdown\",\n\t\t\t\t\t\"label\": \"Select logging level:\",\n\t\t\t\t\t\"items\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"INFO\",\n\t\t\t\t\t\t\t\"label\": \"Info\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"WARNING\",\n\t\t\t\t\t\t\t\"label\": \"Warning\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"ERROR\",\n\t\t\t\t\t\t\t\"label\": \"Error\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"CRITICAL\",\n\t\t\t\t\t\t\t\"label\": \"Critical\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"value\": \"DEBUG\",\n\t\t\t\t\t\t\t\"label\": \"Debug\"\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t\"required\": true,\n\t\t\t\t\t\"placeholder\": \"\",\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"_sda_optional_settings_section\",\n\t\t\t\t\t\"type\": \"section\",\n\t\t\t\t\t\"label\": \"Optional settings\",\n\t\t\t\t\t\"open\": false,\n\t\t\t\t\t\"visible\": \"\",\n\t\t\t\t\t\"indent\": 0,\n\t\t\t\t\t\"children\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_batch_tag\",\n\t\t\t\t\t\t\t\"type\": \"textfield\",\n\t\t\t\t\t\t\t\"label\": \"Provide an optional batch tag identifier:\",\n\t\t\t\t\t\t\t\"placeholder\": \"ex. Batch_123ABC\",\n\t\t\t\t\t\t\t\"required\": false,\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_esb_batch_tag_txt\",\n\t\t\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\t\t\"text\": \"The optional batch tag identifier allows users to group files by a common label.\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_bypass_ssl_security\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Bypass SSL security check\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_skip_re_ocr\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Avoid duplicate OCR calls\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_use_uuid_as_name\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Assign UUID to file names\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_keep_subdirectories\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Maintain source directory structure\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_delete_source_files\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Remove source files\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"_sda_wait_for_completion\",\n\t\t\t\t\t\t\t\"type\": \"checkbox\",\n\t\t\t\t\t\t\t\"label\": \"Wait for batch execution before terminating (synchronous processing)\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"id\": \"pageAbout\",\n\t\t\t\"type\": \"page\",\n\t\t\t\"label\": \"About\",\n\t\t\t\"children\": [\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"textAbout\",\n\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\"text\": \"OCR - Document Analysis - Execute Batch OCR Process step\\n==========\\n\\nThe \\\"OCR - Document Analysis - Execute Batch OCR Process\\\" custom steps enables an easy integration with the SAS Document Analysis (SDA) model, to run a full batch job, without the need to write any code.\\n\\nThe following cloud OCR engines are supported: \\n * Microsoft OCR\\n * AWS Textract\\n\\nThe location of the generated output will be displayed for after running this step.\\n\",\n\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"sectionPrereqs\",\n\t\t\t\t\t\"type\": \"section\",\n\t\t\t\t\t\"label\": \"Pre-requisites\",\n\t\t\t\t\t\"open\": false,\n\t\t\t\t\t\"visible\": \"\",\n\t\t\t\t\t\"children\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"textPrereqs\",\n\t\t\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\t\t\"text\": \"A license for SAS Document Analysis (SDA) is required and you will need to know the ID of the launch context that was created during the deployment of SDA.\\n\\nPre-requisites: Tested on Viya version Stable 2024.08\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"sectionDocumentation\",\n\t\t\t\t\t\"type\": \"section\",\n\t\t\t\t\t\"label\": \"Documentation\",\n\t\t\t\t\t\"open\": false,\n\t\t\t\t\t\"visible\": \"\",\n\t\t\t\t\t\"children\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"textDocumentation\",\n\t\t\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\t\t\"text\": \"* SAS Document Analysis documentation (https://go.documentation.sas.com/doc/en/aaimdacdc/default/aaimdawlcm/home.htm)\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": \"sectionChangelog\",\n\t\t\t\t\t\"type\": \"section\",\n\t\t\t\t\t\"label\": \"Changelog\",\n\t\t\t\t\t\"open\": true,\n\t\t\t\t\t\"visible\": \"\",\n\t\t\t\t\t\"children\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"id\": \"textChangelog\",\n\t\t\t\t\t\t\t\"type\": \"text\",\n\t\t\t\t\t\t\t\"text\": \"* Version 1.2 (04NOV2024)\\n - Added option to wait for batch completion with ability to specify a max wait time.\\n\\n* Version 1.1 (09OCT2024)\\n - Implemented feedback\\n\\n* Version: 1.0 (07OCT2024)\\n - Initial version\",\n\t\t\t\t\t\t\t\"visible\": \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t],\n\t\"syntaxversion\": \"1.3.0\",\n\t\"values\": {\n\t\t\"_sda_source_data_directory\": \"\",\n\t\t\"_sda_ocr_engine\": null,\n\t\t\"_sda_launcher_context_id\": \"\",\n\t\t\"_sda_log_level\": {\n\t\t\t\"value\": \"INFO\",\n\t\t\t\"label\": \"Info\"\n\t\t},\n\t\t\"_sda_batch_tag\": \"\",\n\t\t\"_sda_bypass_ssl_security\": false,\n\t\t\"_sda_skip_re_ocr\": true,\n\t\t\"_sda_use_uuid_as_name\": false,\n\t\t\"_sda_keep_subdirectories\": true,\n\t\t\"_sda_delete_source_files\": false,\n\t\t\"_sda_wait_for_completion\": true\n\t}\n}","templates":{"SAS":"* _sda_ is short for Execute SDA Batch, where SDA stands for SAS Document Analysis;\ndata _null_;\n * Check that the user provided a valid ID for the launcher context;\n if not prxMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', \"&_sda_launcher_context_id.\") then do;\n putLog 'ERROR: The provided launcher context ID is not valid.';\n abort 42;\n end;\n\n * Check that the user provided a source directory on the SAS server and not in SAS Content;\n mode = scan(\"&_sda_source_data_directory.\", 1, ':', 'MO');\n if mode EQ 'sasserver' then do;\n call symputx('_sda_src_dirpath', scan(\"&_sda_source_data_directory.\", 2, ':', 'MO'));\n end;\n else do;\n putLog 'ERROR: Please ensure that the selected source directory is on the SAS server.';\n abort 42;\n end;\n\n * Check that the batch tag is no longer than 50 characters;\n\tif length(\"&_sda_batch_tag\") > 50 then do;\n putLog 'ERROR: Please ensure that the Batch Tag does not exceed 50 characters.';\n abort 42;\n\tend;\nrun;\n\n* Get the Viya Host URL;\n%let _sda_viya_host=%sysfunc(getoption(SERVICESBASEURL));\n\n/* Preprocess macrovars to convert binary to boolean */\n%if &_sda_skip_re_ocr. %then %do;\n\t%let _sda_skip_re_ocr = True;\n\t%let _sda_force_ocr = False;\n%end;\n%else %do;\n\t%let _sda_skip_re_ocr = False;\n\t%let _sda_force_ocr = True;\n%end;\t\n\n%if &_sda_use_uuid_as_name. %then %do; %let _sda_use_uuid_as_name=True; %end;\n%else %do; %let _sda_use_uuid_as_name = False; %end;\n\n%if &_sda_delete_source_files. %then %do; %let _sda_delete_source_files=True; %end;\n%else %do; %let _sda_delete_source_files = False; %end;\n\n%if &_sda_keep_subdirectories. %then %do; %let _sda_keep_subdirectories=True; %end;\n%else %do; %let _sda_keep_subdirectories=False; %end;\n\n%if &_sda_wait_for_completion. %then %do; %let _sda_wait_for_completion=True; %end;\n%else %do; %let _sda_wait_for_completion = False; %end;\n\n%if %symexist(_sda_max_wait_time_minutes)=0 %then %do; %let _sda_max_wait_time_minutes = 0; %end;\n\n/* Construct HTTP reuqest body */\n%let _sda_http_request_body=%str({ \"name\":\"sda-batch-ocr-process\",\n \"description\":\"Execute OCR Process Using SAS Document Analysis\",\n \"command\":\"python process/sda-ocr/scripts/run_sda_batch.py\",\n \"contextId\":\"%superq(_sda_launcher_context_id)\",\n \"environment\":{\n \"SOURCE_DATA_DIRECTORY\":\"%superq(_sda_src_dirpath)\",\n \"OCR_ENGINE\":\"%superq(_sda_ocr_engine)\",\n \"SKIP_RE_OCR\": \"%superq(_sda_skip_re_ocr)\",\n \"FORCE_OCR\": \"%superq(_sda_force_ocr)\",\n \"LOG_LEVEL\": \"%superq(_sda_log_level)\",\n \"USE_UUID_AS_NAME\": \"%superq(_sda_use_uuid_as_name)\",\n \"DELETE_SOURCE_FILES\": \"%superq(_sda_delete_source_files)\",\n \"KEEP_SUBDIRECTORIES\": \"%superq(_sda_keep_subdirectories)\",\n \"BATCH_TAG\": \"%superq(_sda_batch_tag)\"\n }, \n \"kubernetes\": {\"jobNamePrefix\": \"sda-execute-ocr-\"} \n });\n\nfilename _sda_out temp; \n\n* Start a SAS launcher process, which will in turn run the SDA process;\nproc http\n method='POST' \n url = \"&_sda_viya_host./launcher/processes\" \n in = %tslit(&_sda_http_request_body)\n oauth_bearer = sas_services\n out = _sda_out; \n headers 'Accept' = 'application/vnd.sas.launcher.process+json'; \n headers 'Content-Type' = 'application/json';\n %if &_sda_bypass_ssl_security. %then %do;\n SSLPARMS \"SSLREQCERT\" = \"ALLOW\";\n %end;\t\t\nquit;\n\n%if %symexist(SYS_PROCHTTP_STATUS_CODE) %then %do;\n\t* HTTP Status Handling;\n\tdata _null_; \n\t if &SYS_PROCHTTP_STATUS_CODE. lt 400 then do; \n\t putLog 'NOTE: The request to launch the SDA process was successful.'; \n\t putLog \"NOTE: The HTTP Status Code is &SYS_PROCHTTP_STATUS_CODE..\"; \n\t putLog \"NOTE: That means: &SYS_PROCHTTP_STATUS_PHRASE..\"; \n\t end; \n\t else do; \n\t putLog 'ERROR: The request to launch the SDA process was most likely not successful.'; \n\t putLog \"ERROR: The HTTP Status Code is &SYS_PROCHTTP_STATUS_CODE..\"; \n\t putLog \"ERROR: That means: &SYS_PROCHTTP_STATUS_PHRASE..\"; \n\t\t\tabort 42;\n\t end; \n\trun;\n%end;\n%else %do;\n\t* HTTP Status Handling - response code not logged to macrovar;\n\tdata _null_; \n\t putLog 'ERROR: The request to launch the SDA process was most likely not successful.'; \n\t putLog \"ERROR: The HTTP Status Code is unknown.\"; \n\t\t\tabort 42;\n\trun;\n%end;\n\n%let _sda_process = '';\n%let _sda_output_directory = '';\n%let _sda_sas_launcher_process_id = '';\n\n%if %sysfunc(fexist(_sda_out)) %then %do;\n\tlibname _sda_out json;\n\t* Check if a output directory that differs from the default was provided;\n\tdata _null_;\n\t set _sda_out.alldata;\n\t if upcase(P1)='ENVIRONMENT' then do;\n\t if upcase(P2)='OUTPUT_DIRECTORY' then call symput('_sda_output_directory', cats(value));\n\t if upcase(P2)='PROCESS' then call symput('_sda_process', cats(value));\n\t\t\tif upcase(P2)=\"SAS_LAUNCHER_PROCESS_ID\" then call symputx(\"_sda_sas_launcher_process_id\",cats(value),'g');\n\t end;\n\trun;\n\n\t* Inform the user about the outcome of the process;\n\tdata work._sda_message_output;\n\t length sda_launcher_message $500;\n\t if \"&_sda_output_directory.\" ne '' and \"&_sda_process.\" ne '' then do;\n\t sda_launcher_message = 'Logs have been routed to ' || \"&_sda_output_directory./&_sda_process./logs\";\n\t output;\n\t sda_launcher_message = 'Output data has been routed to ' || \"&_sda_output_directory./&_sda_process./data\";\n\t output;\n\t end;\n\t else do;\n\t sda_launcher_message = 'Data and logs have been routed to the default location specified during installation';\n\t output;\n\t end;\n\trun;\n\n\t* Print the launcher information for the user;\n\tproc print data=work._sda_message_output noObs label;\n\t var sda_launcher_message;\n\t\tlabel sda_launcher_message=\"SDA Launcher Message\";\n\tquit;\n\n%end;\n%else %do;\n\tdata _null_; \n\t put 'ERROR: The PROC HTTP response JSON could not be found.';\n\t\t\tabort 42;\n\trun;\n%end;\n\n%global _sda_elapsed_time;\n\n%macro _sda_check_process_status(_sda_start_time=0);\n %if &_sda_start_time = 0 %then %let _sda_start_time = %sysfunc(datetime());\n %let _sda_current_time = %sysfunc(datetime());\n %let _sda_elapsed_time = %sysfunc(round(%sysevalf((&_sda_current_time - &_sda_start_time)/60), 0.01)); /* Convert seconds to minutes */\n\n filename _sda_out clear;\n filename _sda_out temp;\n\n proc http\n method='get'\n url=\"&_sda_viya_host./launcher/processes/&_sda_sas_launcher_process_id./state\"\n oauth_bearer = sas_services\n out=_sda_out;\n headers 'Accept' = 'text/plain';\n quit;\n\n\tdata _null_;\n\t\tcall sleep(5, 1);\n\trun;\n\n\t%if %sysfunc(fexist(_sda_out)) %then %do;\n\t\t%if %symexist(SYS_PROCHTTP_STATUS_CODE) %then %do;\n\t\t data _null_;\n\t\t length status $128.;\n\t\t infile _sda_out;\n\t\t input status $;\n\t\t if &SYS_PROCHTTP_STATUS_CODE. lt 400 then do;\n\t\t if status = 'completed' then do;\n\t\t putLog \"NOTE: SDA process completed successfully.\";\n\t\t end;\n\t\t else if status = 'failed' then do;\n\t\t putLog \"ERROR: SDA process did not complete successfully. Please see SDA batch logs for more information.\";\n\t\t\t\t\t\tabort 42;\n\t\t end;\n\t\t else if %sysevalf(&_sda_elapsed_time >= &_sda_max_wait_time_minutes) and %sysevalf(&_sda_max_wait_time_minutes > 0) then do;\n\t\t putLog \"WARNING: Maximum wait time of &_sda_max_wait_time_minutes minutes reached. Last known process status = \" status;\n\t\t end;\n\t\t else do;\n\t\t * Wait for 5 seconds before making another call;\n\t\t *putLog \"NOTE: Process status = \" status\". Waiting for process to finish.\";\n\t\t call sleep(5, 1);\n\t\t call execute('%_sda_check_process_status(_sda_start_time=&_sda_start_time)');\n\t\t end;\n\t\t end;\n\t\t else do;\n\t\t putLog \"ERROR: The request to check the status of the SDA process was not successful.\"; \n\t\t putLog \"ERROR: The HTTP Status Code is &SYS_PROCHTTP_STATUS_CODE..\"; \n\t\t putLog \"ERROR: That means: &SYS_PROCHTTP_STATUS_PHRASE..\"; \n\t\t\t\t\tabort 42;\n\t\t end; \n\t\t run;\n\t\t%end;\n\t\t%else %do;\n\t\t\t* HTTP Status Handling - response code not logged to macrovar;\n\t\t\tdata _null_; \n\t\t putLog \"ERROR: The request to check the status of the SDA process was not successful.\"; \n\t\t\t putLog \"ERROR: The HTTP Status Code is unknown.\"; \n\t\t\t\t\tabort 42;\n\t\t\trun;\n\t\t%end;\n\t%end;\n\t%else %do;\n\t\tdata _null_; \n\t\t putLog 'ERROR: The PROC HTTP response JSON could not be found.';\n\t\t\t\tabort 42;\n\t\trun;\n\t%end;\n%mend _sda_check_process_status;\n\n%if %str(&_sda_wait_for_completion.) = %str(True) %then %do;\n %_sda_check_process_status();\n%end;\n\n%put _sda_wait_for_completion IS &_sda_wait_for_completion;\n\n* Inform the user about the outcome of the process;\ndata work._sda_message_output;\n length sda_process_message $500;\n\tif \"&_sda_wait_for_completion.\" = \"True\" then do;\n sda_process_message = cat(\"Process executed synchronously in \",\"&_sda_elapsed_time.\",\" minutes\");\n output;\n\tend;\n\telse do;\n sda_process_message = 'Process executed asynchronously. Process may still be running in the background';\n output;\n\tend;\nrun;\n\n* Print the process information for the user;\nproc print data=work._sda_message_output noObs label;\n var sda_process_message;\n\tlabel sda_process_message=\"SDA Process Message\";\nquit;\n\n* Clean up;\nlibname _sda_out clear;\nfilename _sda_out clear;\n%symdel _sda_viya_host _sda_http_request_body _sda_output_directory _sda_process _sda_sas_launcher_process_id\n\t\t_sda_skip_re_ocr _sda_use_uuid_as_name _sda_keep_subdirectories _sda_delete_source_files _sda_wait_for_completion\n\t\t_sda_elapsed_time;\nproc datasets library=work noList;\n delete _sda_message_output;\nrun; quit;"}}