SAS scan

Miss Discontinuity
2 min readSep 5, 2018

--

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

Problem:
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
Example:
a= TF-BOY101000–001–1000
b=Scan (a, 3, ‘-’);
Note: Take the third word separated by “-”.
Return: 001

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

[caption id=”attachment_229" align=”alignnone” width=”1280"]

janjf93 / Pixabay[/caption]

Solution:
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

Code:
1.aeendth=tranwrd(aeendth,”/”,”|”);
2.deathdt=input(scan(aesdthd,-1,’|’),??IS8601DA.);

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 :)

--

--