Posts

Showing posts from September, 2010

How to convert the datetime character string to SAS datetime value? (ANYDTDTM and MDYAMPM formats)

Image
When we have a string like this "9/01/2010 11:52:54 AM" and would like to translate the string to a numeric SAS date time variable, most of the times we use SCAN function to extract the information to get the DATETIME format. This is definitely a tedious job. SAS formats ( MDYAMPM, ANTDTDTM ) comes to rescue us. Here is how it works. data test ; length date $25 ; date=" 9/01/2010 11:52:54 AM "; *Convert the character string to SAS datetime value; datetimevar = input (date, mdyampm25.2 ); datetimevar1 = input (date, anydtdtm20. ); *Apply format to the SAS date time value; format datetimevar datetimevar1  datetime19. ; run ; Result: 01SEP2010:11:52:54 * ANYDTDTM and MDYAMPM informats work together when the datetime value has AM PM specified or day, month, and year components are not ambiguous. The MDYAMPMw . format writes datetime values with separators in the form mm/dd/yy hh:mm AM PM, and requires a space between the date and the time....

SAS Keyboard Shortcuts

Image
Here are the few shortcuts you need to know to speed up the code writing. These work in both EPG (Enterprise Guide) and SAS Enhanced Editor. Shortcuts and their descriptions: Remember that the keyboard shortcuts listed here are default. Selection Operations: 1) Comment the section with line comments (/): press CTL + / 2) Undo the comment: press CTL + SHIFT + / 3) Convert selected text to lowercase: press CTL + SHIFT + L 4) Convert selected text to uppercase: press CTL + SHIFT + U Shortcuts (pre-defined) CTRL+Shift+L or +U (only for the enhanced editor), which convert all selected text into lowercase or uppercase respectively. These become very handy  when we insert the text by copy+paste. 5) Indent selected section: press TAB 6) Un-indent selected section: press SHIFT + TAB 7) To move curser to the matching DO/END statement: press      ALT + [ or      ALT + { or        ALT+] or ...

Mastering Global and Local Macro Variables in SAS: Essential Techniques and Best Practices for SDTM Programmers

Mastering Global and Local Macro Variables in SAS: A Detailed Guide for SDTM Programmers Mastering Global and Local Macro Variables in SAS: A Detailed Guide for SDTM Programmers In SAS programming, especially when dealing with complex tasks such as SDTM (Study Data Tabulation Model) dataset creation, macro variables play a critical role in automating processes and managing large amounts of data efficiently. Understanding the distinction between Global and Local macro variables, and how to use them appropriately, is essential for writing clean, maintainable, and robust code. What are Macro Variables in SAS? Macro variables in SAS are placeholders that store text strings, which can be reused throughout your SAS programs. They are part of the SAS Macro Language and are used to make your code more dynamic and flexible. By using macro variables, you can avoid hardcoding values and make your code easier to modify and scale. There are two pri...