/*** TIP 00382 ***/

A bizarre Use/Example of Comma Informat

Author: Roland Rashleigh-berry & Don Stanley
roland@rashleigh-berry.fsnet.co.uk
don.stanley@NBNZ.CO.NZ

  
data test;  
 infile cards missover;  
 input string $ 20.  ;  
  
 value = input( string, comma20.);  
  
 put value ;  
  
cards;  
5,678  
100 000 000  
0.0, 1  
0.01 5  
678,000 .01  
4.000 001  
5.000.000  
;;;;  
run;  

/*** Here is what is generated by the above test program ***/  
/***  
5678  
100000000  
0.01  
0.015  
678000.01  
4.000001  
NOTE: Invalid argument to function INPUT at line 52 column 10.  
.  
RULE:  ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0  
63  5.000.000  
string=5.000.000 value=. _ERROR_=1 _N_=6  
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to  
  missing values.  
  Each place is given by: (Number of times) at (Line):(Column).  
  1 at 52:10  
NOTE: The data set WORK.TEST has 6 observations and 2 variables.  
NOTE: DATA statement used:  
  real time  0.00 seconds  
  cpu time  0.00 seconds  
  
***/  

Comments from Paul Dorfman paul_dorfman@hotmail.com I have chimed in with this so far in the beginning saying: just take a look at the Compress() function. Nat W. noted privately that Compress() would still produce a string, while it appeared that the asker wanted a numeric variable, not a string. First, let us deal with the COMMA business. The informat does indeed kill some most common characters found in standard numeric strings, but one should not expect it to eliminate any stray byte that might have slipped in. Compressing the string against everthying that is not 0123456789 is the only way to guarantee that the result is a pure digital string. It can be done, for instance, this way: 32 data _null_ ; 33 str = '00'x||'28624pt 8q3&pw8q' || 'aa'x || '15y6215_70we7d=sgh56+23' ; 34 str = compress(str, compress(collate(0,255), '0123456789')) ; 35 put str=; 36 run ; str=286248381562157075623 Secondly, using the INPUT() function to make a numeric variable hold the computable content of STR in its double-float belly makes sense only if the belly is large enough to swallow it in the first place. For the string above, it is certainly too small regardless of the informat used. SAS will swallow only a chunk of it, spitting the rest into a thin air garbage can without a peep of complaint. Imagine that in your own example, the 20-byte input string contains just a couple of stray commas, say str = '123456789012,345,678' ; Comma20. will kill the commas, but also round the last two digits to 80. So, if the original poster indeed wanter a numeric variable, he should be aware of these simple truths, and if he does not intend to compute on the variable, compressing it as indicated above should suffice.
/*** end of tip 00382 ***/