Hi SAS Forum, /*Hi SAS Forum, I have this data set. It shows the postal codes of each account. But the postal_code field has a mix of values. Some are correct, some are strange, some are wrong. */ data have; input account_number postal_code $ 6-12; cards; 1111 T2H 1B5 2222 T9E 6C8 3333 01000 4444 1097C7 5555 123 7777 A0A 1K0 9999 J0N 1G3 8888 11654-2011 1234 T9W 3H2 ; run; /* I wanted to create a new variable called "Validation" with following rules. If a postal code start with T, and it has 6 chractoers, and first charactoer is a letter, second is a numeric, third is a letter, fourth is a space, fifth is a numeric, sixth is a letter, 7th is a numeric then validation = 'correct' If a postal code starts with a letter which is not T, and all the other conditions above are satisfied, then validation = 'wrong' Else validation ='strange' */ /*For clarity, I have indicated below the values of variable "Validation" in front of each record*/ data have; input account_number postal_code $ 6-12 validation; cards; 1111 T2H 1B5 /*correct*/ 2222 T9E 6C8 /*correct*/ 3333 01000 /*strange*/ 4444 1097C7 /*strange*/ 5555 123 /*strange*/ 7777 A0A 1K0 /*wrong*/ 9999 J0N 1G3 /*wrong*/ 8888 T1654-2011 /*strange*/ 1234 T9W 3H2 /*correct*/ ; run; Q: Could someone help me how to do this. Thanks for your time. Miris
... View more