SAS scan

SAS Day 4:

I came across a very interesting variable structure, AEENDTH combined AEENDT(adverse event end date) and DEATHDT (death date) together.
For example, 2008-04-21/2008-05-12

We want the select the non-missing death date (second date), however, if the death date is missing, we will select the adverse event end date (first date) as the death date.

Before we solve the problem, we need to go over a couple of SAS Functions: SCAN, TRANWRD

SCAN: separate a character value into words and return a specified word 
a= TFBOY1010000011000
b=Scan (a, 3, ‘-‘);
Note: Take the third word separated by “-“.
Return: 001 

TRANWRD: substitute strings for a certain part of the variable
Add=No.88 Keyuan Road’;
Add =TRANWRD (Add,’Road’,’Rd.‘);
Note: replace Road with Rd.
Return: No.88 Keyuan Rd. 


janjf93 / Pixabay

1. Apply Tranwrd function to replace “/” with “|”
2. Apply Scan function from last digit (-1) until the “|”
3. Apply Input function to convert the time to numerical, and use ?? to      avoid log warnings


Note: We should NOT use (scan(aesdthd,2,’|’), because some records only have a date, 2008-03-21/

Thanks to 77, she started to summarized the SAS functions and shared it with me 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: