Hello all,
I am importing a csv file that has a variable named bnkrptdate that has a length of 7 and I am using an informat of MMDDYY7. to read it in to SAS.
The problem I am running in to is that if the observation does NOT have a bnkrptdate, the value is 0000000, if it does have a bnkrptdate then the informat works
data have ;
infile datalines delimiter=',' ;
informat contrprofile 16. bnkrpt_ch $2. bnkrptdate mmddyy7. loanclass $2. int_type $1. purchasedate mmddyy7. ;
input contrprofile bnkrpt_ch $ bnkrptdate loanclass $ int_type $ purchasedate ;
datalines ;
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,13,0040218,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,58,I,0081518
0000000000000,00,0000000,59,P,0081518
0000000000000,00,0000000,59,P,0081718
;
format bnkrptdate purchasedate mmddyy10. ;
run;
This is the note I get (from my full dataset):
NOTE: Invalid data for bnkrptdate in line 21 494-500.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.I am just curious how I can work around this issue? Open to any suggestions, thnaks for reading!
1. Read it as character and fix in the next step or within the proc
2. Create a custom informat that sets 000000 to missing (untested)
proc format;
invalue myFormat
'0000000' = .
other = [yymmdd10.];
run;
1. Read it as character and fix in the next step or within the proc
2. Create a custom informat that sets 000000 to missing (untested)
proc format;
invalue myFormat
'0000000' = .
other = [yymmdd10.];
run;
proc format was a great way to go, thank you!
On an input statement you can add the INFORMAT modifier ?? to suppress error messages .
BTW you can't have any code such as your Format statement after a datalines block.
data have ; infile datalines delimiter=',' ; informat contrprofile 16. bnkrpt_ch $2. bnkrptdate mmddyy7. loanclass $2. int_type $1. purchasedate mmddyy7. ; input contrprofile bnkrpt_ch $ bnkrptdate ?? loanclass $ int_type $ purchasedate ; format bnkrptdate purchasedate mmddyy10. ; datalines ; 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,13,0040218,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,58,I,0081518 0000000000000,00,0000000,59,P,0081518 0000000000000,00,0000000,59,P,0081718 ; run;
Thanks, ballardw, for the tip about the ??.
As far as the format statement I just was trying to recreate quickly a small sample of my data, but good to know for future reference.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.