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

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=‘No.88 KeyuanRoad’;

Add =TRANWRD(Add,'Road','Rd.');

Note: replace Road with Rd.

Return: No.88 KeyuanRd. 

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

janjf93/ Pixabay[/caption]

SAS Scan_第1张图片

Solution: 

1. ApplyTranwrdfunction to replace "/" with "|"

2. ApplyScanfunction from last digit (-1) until the "|"

3. ApplyInputfunction 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 shouldNOTuse (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 :)

你可能感兴趣的:(SAS Scan)