Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created November 15, 2018 01:46
Show Gist options
  • Select an option

  • Save statgeek/47759eff5d7ec20aee1ab53bc8788836 to your computer and use it in GitHub Desktop.

Select an option

Save statgeek/47759eff5d7ec20aee1ab53bc8788836 to your computer and use it in GitHub Desktop.
SAS - Example of an informat/convert character to numeric
/*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