mingfeng07 发表于 2013-10-20 23:20 
建议你看一下format语句的用法这一节
SAS help的解释如下,看来用了format过程转换字符到数值,在有字符及数值混合的数据,是必须要用evaluation的,谢谢。
- Program Description
- This program converts quarterly employee evaluation grades, which are alphabetic, into numeric values so that reports can be generated that sum the grades up as points.
- Set up two SAS library references, one named PROCLIB and the other named LIBRARY.
- libname proclib 'SAS-library-1';
- libname library 'SAS-library-2';
- Store the Evaluation. informat in the catalog LIBRARY.FORMATS.
- proc format library=library;
- Create the numeric informat Evaluation. The INVALUE statement converts the specified values. The letters O (Outstanding), S (Superior), E (Excellent), C (Commendable), and N (None) correspond to the numbers 4, 3, 2, 1, and 0, respectively.
- invalue evaluation 'O'=4
- 'S'=3
- 'E'=2
- 'C'=1
- 'N'=0;
- run;
- Create the PROCLIB.POINTS data set. The instream data, which immediately follows the DATALINES statement, contains a unique identification number (EmployeeId) and bonus evaluations for each employee for each quarter of the year (Q1–Q4). Some of the bonus evaluation values that are listed in the data lines are numbers; others are character values. Where character values are listed in the data lines, the Evaluation. informat converts the value O to 4, the value S to 3, and so on. The raw data values 0 through 4 are read as themselves because they are not referenced in the definition of the informat. Converting the letter values to numbers makes it possible to calculate the total number of bonus points for each employee for the year. TotalPoints is the total number of bonus points.
- data proclib.points;
- input EmployeeId $ (Q1-Q4) (evaluation.,+1);
- TotalPoints=sum(of q1-q4);
- datalines;
- 2355 S O O S
- 5889 2 2 2 2
- 3878 C E E E
- 4409 0 1 1 1
- 3985 3 3 3 2
- 0740 S E E S
- 2398 E E C C
- 5162 C C C E
- 4421 3 2 2 2
- 7385 C C C N
- ;
- Print the PROCLIB.POINTS data set. The NOOBS option suppresses the printing of observation numbers.
- proc print data=proclib.points noobs;
- Specify the title.
- title 'The PROCLIB.POINTS Data Set';
- run;
复制代码
看来