List of SAS Viya Global Macros
The global macros provided below have been set up to enable a user to get quick information from Viya to schema/tables in Hive.
SAS Viya Global Macros
Click the appropriate tab to display the macro's name, its purpose, and an example or note about the macro.
Macro | %help() |
---|---|
Purpose | The help macro shows documentation links and provide information on available system macros. |
Example/Note | NA |
Macro | %send_email(to_email, subject, body, attachment); |
---|---|
Purpose | Sends an email from SAS Viya to one or more recipients with an optional attachment. |
Example/Note | %send_email() was updated, and users can no longer specify the sender. from_email parameter is now hardcoded to comply with HCQIS guidelines that all email must sent from a hcqis.org email address. Sender will now always be: ccsq-sas-viya@hcqis.org Important Note: Remove the from_email parameter from the macro calls. %send_email(to_email="me@me.com", %send_email(to_email="me@me.com coworker@me.com", Update %send_email( ); has been updated to send email as HTML and the "Last error" line has been removed. A new parameter - send_html defaults to "Y" to send HTML email: %send_email(to_email="(your email address)", subject="HTML Test", body="<font color=red>Red text</font>"); If you want to send email as plain text set send_html="N" %send_email(to_email="(your email address)", subject="Plain - text", body="Plain text", send_html="N"); Warning Make sure the logs do not include protected health information (PHI)/personally identifiable information (PII)! |
Macro | %list_databases() |
---|---|
Purpose | Lists the databases that are visible to users. |
Example/Note | NA |
Macro | %list_caslibs() |
---|---|
Purpose | Lists the CASLIBs that are visible to users. |
Example/Note | NA |
Macro | %list_tables(schema) |
---|---|
Purpose | Lists the tables in a database. |
Example/Note | %list_tables("nch_part_a"); |
Macro | %list_columns(schema, table) |
---|---|
Purpose | Lists the columns in a table. |
Example/Note | %list_columns(schema="nch_part_a", table="hha_line"); |
Macro | %list_partitions(schema, table) |
---|---|
Purpose | Lists the partitions in a table. |
Example/Note | %list_partitions(csat_201908_baseline, csat_abase_201908_ak); Note: Use partition for filtering in addition to any filter that might already be in use By doing so, it dramatically cuts down on processing time and system resources needed. |
Macro | %show_rowcount(schema, table) |
---|---|
Purpose | Lists row count and size of a table. |
Example/Note | %show_rowcount(csat_201908_baseline, csat_abase_201908_ak); |
Macro | %hive_exec_sql(sql, queue=[unspecified]|heavy); |
---|---|
Purpose | Executes SQL code directly in Hive - recommended over PROC SQL in SAS since it is faster than an implicit PROC SQL in SAS. queue: [unspecified] - use default queue | heavy - use the queue for larger processing tasks. |
Example/Note | %LET sql=%STR(CREATE TABLE &myschema.my_exec_test AS SELECT * FROM claims_sample LIMIT 100); %hive_exec_sql(&sql); %LET sql=%STR(CREATE TABLE &myschema.my_exec_test AS SELECT * FROM claims_sample LIMIT 100); |
Macro | %hive_drop_table(schema,table) |
---|---|
Purpose | Drops the schema.table indicated in Hive. |
Example/Note | NA |
Macro | %usage_hive(schema, [show_tables=Y]); |
---|---|
Purpose | Shows the amount of space used by a user's project database and optionally details on each individual table. |
Example/Note | %usage_hive(); * Show usage for all project databases a particular user has access to; %usage_hive(schema="damod"); * Show the total usage for the damod schema [insert user's own schema name]; %usage_hive(schema="damod", show_tables=Y); * Show usage for each table in the damod schema [update for a user's schema]; |
Macro | %gzip(source_file); |
---|---|
Purpose | Compresses a single file with gzip compression and outputs to the same folder. |
Example/Note | %gzip(source_file=[full path to source file]); |
Macro | %gunzip(gzip_file); |
---|---|
Purpose | Uncompress a single gzipped file to the same folder. |
Example/Note | %gunzip(gzip_file=[full path to .gz file]); |
Macro | %hive_explain(sql); |
---|---|
Purpose | Shows the Hive execution plan for the SQL query passed. |
Example/Note | %LET sql=%STR(CREATE TABLE &myschema.show_the_plan AS SELECT * FROM claims_sample.hha_header LIMIT 100); |
Macro | %queue_status(); |
---|---|
Purpose | Shows users information about the Hive queue. Three sections:
|
Example/Note | Note: Active queries only display when users have used %hive_exec_sql() or PROC SQL – CASLIB loads operate differently and will not appear. |
Macro | %zip(); |
---|---|
Purpose | %zip();Compresses a folder with zip compression. There is no deletion of any files in zipping, the macro creates copies which are then zipped. |
Example/Note | %zip(zip_file=file_name_of_zip, source_folder=full_path_to_zip); |
Macro | %ps(); |
---|---|
Purpose | %ps(); will show a list of processes that a user is running - both the interactive window and any background or scheduled tasks. |
Example/Note |
Macro | %queue_status(); |
---|---|
Purpose | %queue_status(); will show the process identification (PID) of the SAS process running a Hive query. |
Example/Note |
Macro | %kill(); |
---|---|
Purpose | %kill(); will allow users to kill their own process. |
Example/Note | %kill(PID); Important Users can only kill their own process - if they submit a process identification (PID) that is for another user or that is invalid, the request will be ignored. Note It will take a few minutes for the process to be killed. |
Macro | %job_start( ); %job_status( ); %job_stop( ); |
---|---|
Purpose | To improve the ability to manage long-running or background tasks, three more macros have been added: %job_start( ); - will start writing log file to current workbench folder. %job_starus( ); - will write an update to the log file and optionally send an email update with a copy of the log file so far. %job_stop( ); - will end logging and send an email with the completed log file. |
Example/Note | Important Make sure the logs do not include protected health information (PHI)/personally identifiable information (PII)! An example of batch processing/logging: 1) Set the log levels (igh, normal, none): %log_level(high); 2) Required: Set the email address: %LET BATCH_USER_EMAIL=youremail@adress.com; 3) Start batch processing code: %job_start(); 4) Run the code (note: no PHI in the following code): DATA work.cars; SET sashelp.car; RUN; 5) Stop batch processing: %job_stop(); |
Macro | %search_cdr( ); |
---|---|
Purpose | %search_cdr( ); will allow users to search the Centralized Data Repository (CDR) database/schema names, table names, and column names. |
Example/Note | Basic Search
Composite Search
|
Macro | %usage_workbench( ); |
---|---|
Purpose | %usage_workbench( ); will allow users to view the amount of space they are using in their workbench. |
Example/Note | Example usage:
|