Posts

Showing posts with the label Macro

Macro Debugging Options in SAS

Macro Debugging Options in SAS Macro Debugging Options in SAS The SAS Macro Facility is a powerful feature that allows for dynamic code generation and automation. However, when macros become complex, it can be challenging to understand how they are executing and where issues might arise. SAS provides several debugging options to help developers trace the execution of macros and diagnose problems. In this article, we will explore the following debugging options: MPRINT MLOGIC SYMBOLGEN MACROGEN MFILE MPRINT The MPRINT option is used to display the SAS statements that are generated by macro execution. This option helps you see the actual code that a macro produces, which is essential for understanding what your macro is doing. Basic Example: options mprint; %macro greet(name); %put Hello, &name!; %mend greet; %greet(Sarath); When you run the above code with the...

Macros are powerful tools in SAS programming, especially in SDTM

Macros are powerful tools in SAS programming, especially in SDTM (Study Data Tabulation Model) programming, where they can automate repetitive tasks and ensure consistency across datasets. However, debugging macros can be challenging due to their complexity and the way they handle data. This guide provides detailed strategies and examples for effectively debugging macros in SDTM programming. 1. Use the MPRINT Option to Trace Macro Execution The MPRINT option in SAS helps trace the execution of macro code by printing the SAS statements generated by the macro to the log. This is especially useful when you want to see the resolved code that the macro generates. Example: Consider a macro that generates an SDTM domain. By enabling MPRINT , you can see exactly what code is being executed, helping you identify where errors might occur. options mprint; %macro create_dm; data dm; set rawdata; usubjid = subject_id; age = input(age_raw, 8.); sex = gender; ...

How to create a macro variable containing a list of variables in a DATA set

Sometimes it is very handy to have a macro variable contanining the variables names of the dataset. Here are the 2 different ways you can create a macro variable with list of variables names ... *Method1: Using Proc Contents and Proc SQL; proc contents data =sashelp.class out =class; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit ; %put &vars; *Method2: Using SASHELP tables and Proc SQL; data class; set sashelp.vcolumn(where=(libname= "SASHELP" and memname= "CLASS" )); keep name; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit; %put &vars;

maxvarlen_macro: Check the Length of all character variables length is LT 200

MAXVARLEN Macro: According to FDA released the Guidance for Industry: Providing Regulatory Submission in Electronic Format – NDAs which was released in Jan 1999, one of the important point to comply with the agency’s regulations is : The length of any character values cannot be more than 200 characters. Here is the macro which will give us the list of character variables whose actual length (not the assigned) is greater than 200. You can use this program to check the maximum length of all variables of any dataset at once. This macro will create a table with list of variables and their length. ***********************************************************************; *** Program: macro_maxvarlen.sas ***; *** Version: 1.0 ***; *** Client: ***; *** Protocol: ***; *** Programmer: sarath Annapareddy ***; *** Date: 22APR2009 ***; *** Purpose: Macro used to check the list of variables whose ***; *** length is GT 200. ***; *** ***; **************************************************...

How to check if the File is exist or not in SAS

How to check if the File is exist or not in SAS: Guys… Let me try explaining how to check if the file exist in the library or directory using SAS. Here I am writing a macro to check if the file exist in the directory or not. Here is the way to check it… % macro check(dir= ) ; %if %sysfunc ( fileexist (&dir)) %then %do; % put File Exists ; % end ; %else %do ; %put File doesn’t exist.; % end ; % mend ; %check (dir=" C:\Documents and Settings\sannapareddy\Desktop\Holidays 2009.docx" ); %sysfunc option empowers me to use the same Data step functions outside the Data step. Almost all of the Data step functions are available to use outside the data step if we use %sysfunc. fileexist option, verifies the existence of an external file. It can also verifies the SAS library. Here is another simple technique to check..... data _null_ ; x= filexist( 'C:\Documents and Settings\sannapareddy\Desktop\Holidays 2009.docx' ); call...