I'm reading in a file with loads of fields from a txt file. I'm having a couple of problems with the formatting
One of the fields is a date field with length 10 in the format 01/01/2010 but it also contains blanks where the date missing.
Here is my code
DATA PC ;
INFILE PC DLM =',' DSD MISSOVER DSD LRECL = 2000 ;
FORMAT
EXPIRY_DATE ddmmyy10.
Comm 17.2
;
input
EXPIRY_DATE ddmmyy10.
Comm 17.2
;
run;
To allow for the blanks, do I need to read it in as a character and then create a new variable with the correct format using sas code.
Also, is there a way to convert to sasdate in the input statement?
One of the other fields, Comm is length 17 in the txt file (including the decimal point) and had two decimal places. Is the above format correct? ie is the 17 in 17.2 the total length of the field including decimal points and .2 the number of decimal places?
Do not use formats in the input statements, because formatted input ignores the delimiter,
Specify the informats with an INFORMAT statement and then use list input without formats.
In addition to KurtBremser's suggestion, also note that the 17.2 informat might be incorrect. You might be better off with an informat of 17.
The difference occurs when the incoming data does not contain a decimal point. If the incoming data contains "12345", for example:
"12345" with 17. informat ==> 12345
"12345" with 17.2 informat ==> 123.45
As an informat, 17.2 looks for decimal points and inserts them when the incoming string does not contain a decimal point.
Finally, note that you may not be able to store exactly a numeric that contains 16 significant digits. You might lose a little precision from the end of the value.
Good luck.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.