Amit Makhija
Amit Makhija

Reputation: 43

Proc informat using cntlin option

I am trying to make character informat from the range values given in a dataset.

Dataset : Grade

Start End Label Fmtname Type  
    0  20 A     $grad   I  
   21  40 B     $grad   I  
   41  60 C     $grad   I  
   61  80 D     $grad   I  
   81 100 E     $grad   I

And here is the code i wrote to create the informat

proc format cntlin = grade;  
run;

And now the code to create a temp dataset using the new informat

data temp;  
    input grade : $grad. @@ ;
datalines;  
21 30 0 45 10
;

The output i wanted was a dataset Temp with values :

Grade  
A  
B  
A  
..

Whereas the dataset Temp has values :

Grade  
   21  
   30  
    0  
   ...

SAS Log Entry :

1146  proc format cntlin = grade;  
NOTE: Informat $GRAD has been output.  
1147  run;
NOTE: PROCEDURE FORMAT used (Total process time):  
      real time           0.01 seconds  
      cpu time            0.01 seconds  

NOTE: There were 5 observations read from the data set WORK.GRADE.


1148  
1149  
1150  data temp;  
1151      input grade : $grad. @@ ;  
1152  
1153  datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a
line.  
NOTE: The data set WORK.TEMP has 5 observations and 1 variables.  
NOTE: DATA statement used (Total process time):  
      real time           0.03 seconds  
      cpu time            0.03 seconds

I am not able to understand why informat is not working. Can anyone please explain where i am making my mistake.

Upvotes: 1

Views: 1168

Answers (1)

Joe
Joe

Reputation: 63434

INFORMATS convert characters to (characters or numbers). So you can't use START/END the way you are doing so, since that only works with numbers.

See the following:

proc format;
invalue $grade
'0'-'20'="A"
'21'-'40'="B"
'41'-'60'="C"
'61'-'80'="D"
'81'-'100'="E";
quit;

proc format;
invalue $grade
'21'='A';
quit;

The latter works, the former gives you an error. So, you could write a dataset with all 101 values (each on a line with START), or just write a format and do it in a second step (read in as a number and then PUT to the format).

Upvotes: 1

Related Questions