Revision: 10160
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 10, 2008 15:46 by webonomic
Initial Code
/* Convert a character value to a numeric value by using the INPUT */
/* function. Specify a numeric informat that best describes how to */
/* read the data value into the numeric variable. */
/* */
/* When changing types a new variable name is required. If you need */
/* to keep the original variable name for the new type, use the */
/* RENAME= option as illustrated in Sample 2. */
data char;
input string :$8. date :$6.;
numeric=input(string,8.);
sasdate=input(date,mmddyy6.);
format sasdate mmddyy10.;
datalines;
1234.56 031704
3920 123104
;
proc print;
run;
/* Convert a numeric value to a character value by using the PUT */
/* function. Specify a numeric format that describes how to write */
/* the numeric value to the character variable. To left align */
/* the resulting character value, specify -L after the format */
/* specification. */
/* */
/* When changing types a new variable name is required. If you need */
/* to keep the original variable name, use the RENAME= option on */
/* the SET statement to rename the variable as it comes into the PDV. */
/* This allows the original variable name to be reused when you */
/* change type. */
data now_num;
input num date: mmddyy6.;
datalines;
123456 110204
1000 120504
;
data now_char;
set now_num (rename=(num=oldnum date=olddate));
num=put(oldnum,6. -L);
date=put(olddate,date9.);
run;
proc print;
run;
Initial URL
http://jaredprins.squarespace.com/blog/2008/12/12/convert-from-character-to-numberic-and-back-using-sas.html
Initial Description
Original Source from http://support.sas.com/kb/24/590.html
Initial Title
Convert values from character to numeric or from numeric to character
Initial Tags
convert
Initial Language
SAS