3.10.08

SAS COLON MODIFIER “ =: ”
Prepared by : Sujith K G.

Usually we use substr () function to select a string which starts with specific characters or for selecting a part of a string. We can also use Sas Colon Modifier “=:” for performing the same task. Both methods allow comparison of values based on the prefix of a text string. Both these methods have been explained using the following example

Here we have a dataset adverse which contains patient id and name of adverse event.

data adverse;
Input id ae $;
cards;
001 asthma
002 chesttightness
003 dizziness
004 cold
005 headache
006 dysphonia
007 commoncold
008 nausea
009 cough
;
run;

We are interested to flag the adverse events starting with “co” namely cough, cold and common cold as Yes and others as No.

This can be performed by using the SUBSTR() function as described below

data event;
set adverse;
if lowcase(substr(ae,1,2))='co' then res="Yes";
else res="No";
run;

The same purpose can be served by applying the Colon Modifier “=:” as described in the following steps

Now using, Colon Modifier the condition is,

data event;
set adverse;
if lowcase(ae) =: "co" then res="Yes";
else res="No";
run;

As can be seen from the above examples in the substring function we need to specify the position to extract the first two letters while in Colon modifier such a requirement is not needed.

No comments: