To convert a numeric value to a character value: use 'put' function with a format.
To convert a character value to a numeric value use 'input' fuction with informat.
But be very careful with the values with decimals, the following code tells you using different formats and informat s can give you really different results.
Using z7. format can help you to insert leading zeros ( '0002007') . To convert correct character variable you should use enough width of your infomat, at least 7 for this data, and then tell sas the last digit is a decimal.
data a;
input year yeartxt $;
cards
; 2007 02007.2
;
run
; data
b; set
a; year1=put(year,
f4.); year2=put(year,
z7.); yeartxt1=input(yeartxt,
f4.); yeartxt2=input(yeartxt,
f5.); yeartxt3=input(yeartxt,
f6.); yeartxt4=input(yeartxt,
f7.); yeartxt5=input (yeartxt,
f2.1); yeartxt6=input (yeartxt,
f3.1); yeartxt7=input (yeartxt,
f4.1); yeartxt8=input (yeartxt,
f5.1); yeartxt9=input (yeartxt,
f6.1); yeartxt10=input (yeartxt,
f7.1); run
; proc
print data=b; run; Answer: year1 and year2 are both correct. Only yeartxt4 and yeartxt10 are correct!
[此贴子已经被作者于2007-2-15 6:57:45编辑过]