Created
November 15, 2018 01:46
-
-
Save statgeek/47759eff5d7ec20aee1ab53bc8788836 to your computer and use it in GitHub Desktop.
SAS - Example of an informat/convert character to numeric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*This is an exmaple of how to create an informat for a character variable. | |
| It converts a character variable to a numeric one as well. | |
| Author: F. Khurshed | |
| Date: 2018-11-14 | |
| */ | |
| *create format; | |
| proc format; | |
| invalue $ grade_fmt | |
| 'A' = 1 | |
| 'B' = 2 | |
| 'C' = 3 | |
| 'D' = 4 | |
| other = 99; | |
| run; | |
| *generate sample data; | |
| data have; | |
| input grade $; | |
| cards; | |
| A | |
| B | |
| C | |
| D | |
| E | |
| A | |
| F | |
| D | |
| ; | |
| run; | |
| *example usage | |
| data want; | |
| set have; | |
| grade_num = input ( grade, $grade_fmt.); | |
| run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment