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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.