Examples use generated data (datalines) to ensure code autonomy.
1 Code Block
PROC DMSRVDATASVC Data
Explanation : This example illustrates the simplest use of the DMSRVDATASVC procedure. It creates an input dataset `work.insrv` with names and addresses. Then, it executes a service named 'StandardizeAddresses' (which must exist on the DataFlux server) using this dataset as input and stores the results in `work.outsrv_basic`. Finally, it displays the output dataset.
Copied!
DATA work.insrv;
LENGTH Name $30 Address $50;
INPUT Name $ Address $;
DATALINES;
John Doe 123 Main St
Jane Smith 456 Oak Ave
;
RUN;
PROC DMSRVDATASVC
SERVICE='StandardizeAddresses'
DATA=work.insrv
OUT=work.outsrv_basic;
RUN;
PROC PRINT DATA=work.outsrv_basic;
TITLE 'Results of the basic standardization service';
RUN;
1
DATA work.insrv;
2
LENGTH Name $30 Address $50;
3
INPUT Name $ Address $;
4
DATALINES;
5
John Doe 123 Main St
6
Jane Smith 456 Oak Ave
7
;
8
RUN;
9
10
PROC DMSRVDATASVC
11
SERVICE='StandardizeAddresses'
12
DATA=work.insrv
13
OUT=work.outsrv_basic;
14
RUN;
15
16
PROC PRINTDATA=work.outsrv_basic;
17
TITLE 'Results of the basic standardization service';
18
RUN;
2 Code Block
PROC DMSRVDATASVC Data
Explanation : This example shows how to specify additional options when executing a service. In addition to `SERVICE`, `DATA`, and `OUT`, it uses `SERVER` to explicitly designate the DataFlux server (here 'localhost') and `PORT` for a non-standard port (21037). The `LOG` option is added to capture service error or information messages in a SAS dataset.
Copied!
DATA work.input_data;
LENGTH Email $50;
INPUT Email $;
DATALINES;
test @example.com
invalid-email
another.one @domain.co.uk
;
RUN;
PROC DMSRVDATASVC
SERVICE='EmailValidationService'
SERVER='localhost'
PORT=21037
DATA=work.input_data
OUT=work.output_data_intermediate
LOG=work.service_log;
RUN;
PROC PRINT DATA=work.output_data_intermediate;
TITLE 'Results of the email validation service';
RUN;
PROC PRINT DATA=work.service_log;
TITLE 'Service execution log';
RUN;
1
DATA work.input_data;
2
LENGTH Email $50;
3
INPUT Email $;
4
DATALINES;
5
test @example.com
6
invalid-email
7
another.one @domain.co.uk
8
;
9
RUN;
10
11
PROC DMSRVDATASVC
12
SERVICE='EmailValidationService'
13
SERVER='localhost'
14
PORT=21037
15
DATA=work.input_data
16
OUT=work.output_data_intermediate
17
LOG=work.service_log;
18
RUN;
19
20
PROC PRINTDATA=work.output_data_intermediate;
21
TITLE 'Results of the email validation service';
22
RUN;
23
24
PROC PRINTDATA=work.service_log;
25
TITLE 'Service execution log';
26
RUN;
3 Code Block
PROC DMSRVDATASVC Data
Explanation : This advanced example simulates batch processing of customer names using a standardization service. The `ERRORONFAILURE=YES` option is crucial here: it instructs SAS to generate an error if the DataFlux service fails, which is useful for integration into automated processing chains. The code includes a simple macro to check the success of the operation via the dataset open return code, programmatically signaling errors.
Copied!
DATA work.customer_names;
LENGTH CustomerID 8 FirstName $20 LastName $20;
INPUT CustomerID FirstName $ LastName $;
DATALINES;
1 John Doe
2 Jane Smith
3 PETER J. JONES
4 mary_ann
;
RUN;
PROC DMSRVDATASVC
SERVICE='NameStandardizationBatch'
DATA=work.customer_names
OUT=work.standardized_names
ERRORONFAILURE=YES;
RUN;
/* Vérifier les erreurs potentielles dans le log */
%MACRO CheckLog;
%LOCAL rc;
%LET rc = %SYSFUNC(OPEN(WORK.standardized_names, I));
%IF &rc EQ 0 %THEN %DO;
%PUT NOTE: The service executed successfully.;
%LET rc = %SYSFUNC(CLOSE(&rc));
%END;
%ELSE %DO;
%PUT ERROR: The service failed. Check the SAS log for more details.;
%END;
%MEND CheckLog;
%CheckLog;
PROC PRINT DATA=work.standardized_names;
TITLE 'Standardized Customer Names';
RUN;
1
DATA work.customer_names;
2
LENGTH CustomerID 8 FirstName $20 LastName $20;
3
INPUT CustomerID FirstName $ LastName $;
4
DATALINES;
5
1 John Doe
6
2 Jane Smith
7
3 PETER J. JONES
8
4 mary_ann
9
;
10
RUN;
11
12
PROC DMSRVDATASVC
13
SERVICE='NameStandardizationBatch'
14
DATA=work.customer_names
15
OUT=work.standardized_names
16
ERRORONFAILURE=YES;
17
RUN;
18
19
/* Vérifier les erreurs potentielles dans le log */
%PUT ERROR: The service failed. Check the SAS log for more details.;
29
%END;
30
%MEND CheckLog;
31
32
%CheckLog;
33
34
PROC PRINTDATA=work.standardized_names;
35
TITLE 'Standardized Customer Names';
36
RUN;
4 Code Block
PROC DMSRVDATASVC Data
Explanation : This example demonstrates the integration of the DMSRVDATASVC procedure into a SAS Viya environment with CAS tables. It initializes a CAS session and creates a CAS table (`mycas.raw_products`). The DMSRVDATASVC procedure is then called, specifying this CAS table as input. The data quality service (here 'ProductDescriptionCleanse') processes the table in distributed memory, and the results are stored in a new CAS table (`mycas.cleaned_products`). PROC CASUTIL and PROC PRINT commands are used to verify the CAS tables and display the processed data, highlighting in-memory processing.
Copied!
CAS;
CASLIB _ALL_ ASSIGN;
DATA _NULL_;
CALL SYMPUTX('CAS_SESSION_NAME', %SYSFUNC(GETOPTION(CASAUTOSESS)));
RUN;
/* Création d'une table CAS à partir de données SAS */
DATA mycas.raw_products;
LENGTH ProductID $10 Description $100;
INPUT ProductID $ Description $;
DATALINES;
P001 Hand Sanitizer 500ml
P002 Hand sanitizer 100ml
P003 Hand SANITIZER 200 ml
;
RUN;
/* Exécution du service Data Quality sur la table CAS */
PROC DMSRVDATASVC
SERVICE='ProductDescriptionCleanse'
DATA=mycas.raw_products
OUT=mycas.cleaned_products;
RUN;
/* Affichage des résultats de la table CAS */
PROC CASUTIL SESSREF=&CAS_SESSION_NAME;
LIST TABLES / CASLIB='CASUSER';
QUIT;
PROC PRINT DATA=mycas.cleaned_products;
TITLE 'Product Descriptions Cleaned via CAS';
RUN;
/* Création d'une table CAS à partir de données SAS */
9
DATA mycas.raw_products;
10
LENGTH ProductID $10 Description $100;
11
INPUT ProductID $ Description $;
12
DATALINES;
13
P001 Hand Sanitizer 500ml
14
P002 Hand sanitizer 100ml
15
P003 Hand SANITIZER 200 ml
16
;
17
RUN;
18
19
/* Exécution du service Data Quality sur la table CAS */
20
PROC DMSRVDATASVC
21
SERVICE='ProductDescriptionCleanse'
22
DATA=mycas.raw_products
23
OUT=mycas.cleaned_products;
24
RUN;
25
26
/* Affichage des résultats de la table CAS */
27
PROC CASUTIL SESSREF=&CAS_SESSION_NAME;
28
LIST TABLES / CASLIB='CASUSER';
29
QUIT;
30
31
PROC PRINTDATA=mycas.cleaned_products;
32
TITLE 'Product Descriptions Cleaned via CAS';
33
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.