BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GBL__
Quartz | Level 8

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 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

GBL__
Quartz | Level 8

proc format was a great way to go, thank you!

ballardw
Super User

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;
GBL__
Quartz | Level 8

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3382 views
  • 3 likes
  • 3 in conversation