CMENRTPT vs CMENRF in SDTM
Understanding CMENRTPT vs CMENRF in SDTM
By Sarath
Introduction
When working with the Concomitant Medication (CM) domain in SDT…
CMENRTPT vs CMENRF in SDTM
Understanding CMENRTPT vs CMENRF in SDTM
By Sarath
Introduction
When working with the Concomitant Medication (CM) domain in SDT…
Resolving the SAS EG Transcoding Error
Addressing the “Character Data Lost During Transcoding” Issue in SAS EG
Author: Sarath
Date: November 19, 2024
Introduction
…
In the SAS 9.4 world, SAS Stored Processes (STP) were incredibly popular. An STP is a SAS program that is stored on a server and can be executed as required by requesting applications. On SAS 9.4, they were widely used for web reporting, analytics, building web applications, delivering packages to […]
Interesting use cases of SAS job web applications was published on SAS Users.
Advanced SAS Programming Techniques for SDTM ImplementationDate: November 3, 2024In the realm of clinical trials data management, SDTM (Study Data Tabulation Model) implementation requires sophisticated programming techniques to ensure data accuracy an…
As SAS programmers, we often encounter situations where we need to execute a certain procedure or set of steps multiple times, typically based on different subsets of data. Manually writing out code for each instance can be time-consuming, but SAS offers a powerful tool to make this process more efficient: CALL EXECUTE
.
CALL EXECUTE
is a SAS routine that allows you to dynamically generate and execute SAS code during a data step’s execution. Instead of hardcoding the logic for every individual case, CALL EXECUTE
can generate the code on the fly and execute it as part of the same data step. This technique is invaluable when you have repetitive tasks across different datasets, procedures, or even report generation.
Let’s say you have multiple datasets in the WORK library, and you want to run a PROC PRINT
for each dataset. Instead of manually writing a PROC PRINT
for each one, you can use CALL EXECUTE
to automate this process:
proc sql;
select cat('proc print data=', libname, '.', memname, '; run;')
into :code_list separated by ' '
from sashelp.vtable
where libname='WORK';
quit;
data _null_;
call execute("&code_list");
run;
This code does the following:
PROC SQL
step queries the SAS dictionary table sashelp.vtable
to generate a list of all datasets in the WORK library. It concatenates each dataset name into a PROC PRINT
statement and stores them in the macro variable code_list
.CALL EXECUTE
routine inside the DATA _NULL_
step dynamically executes each PROC PRINT
statement, printing each dataset without manual intervention.The ability to dynamically generate and execute code gives you tremendous flexibility. Here are some key benefits:
CALL EXECUTE
to run procedures on multiple datasets, making automation easier in iterative tasks like generating reports.In some cases, you might want to execute different procedures based on the content of the data. Here’s an example where we execute PROC FREQ
if a dataset contains a categorical variable, and PROC MEANS
if it contains a numeric variable:
data _null_;
set sashelp.vcolumn(where=(libname='WORK'));
if type = 'char' then
call execute('proc freq data=work.' || trim(memname) || '; tables ' || name || '; run;');
else if type = 'num' then
call execute('proc means data=work.' || trim(memname) || '; var ' || name || '; run;');
run;
In this code:
sashelp.vcolumn
table provides information about the columns in each dataset, including the variable type (character or numeric).CALL EXECUTE
runs either PROC FREQ
for categorical data or PROC MEANS
for numeric data.Using CALL EXECUTE
in SAS is an efficient way to dynamically generate and execute code, particularly in situations that involve repetitive tasks. Whether you’re working on large datasets or need to run different procedures conditionally, CALL EXECUTE
can significantly simplify your workflow and reduce manual intervention. Mastering this tool will help make your SAS programming more efficient and flexible.
Have you used CALL EXECUTE
in your SAS programs? Share your experiences in the comments below!
Finding Duplicate Records Across SAS Datasets in an Entire Library
Finding Duplicate Records Across SAS Datasets in an Entire Library
Author: Sarath
Date: October 10, 2024
Introduc…