DATA Step, Macro, Functions and more

Error for date

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Error for date

[ Edited ]

I think I am asking very basic question but I could not find any reason why this error is happening.

 

I was making simple data set to understand how merge works. Then for the code below, I got an error massage saying invalid data.

 

data test.Merge_test_1;
input Id startdate date9. enddate date9. Value1;
datalines;
120 01JAN2000 01JAN2000 13
120 01JAN2000 01FEB2000 13
120 01FEB2000 01APR2000 15
120 01APR2000 01MAY2000 19
120 01MAY2000 01Dec2000 5
;
run;

 

SAS tells me that there's problem with variable enddate, but since startdate data is working fine, I cannot understand what is wrong with this code. Just in case it might help, I am putting log as well. 

 

183 data test.Merge_test_1;
184 input Id startdate date9. enddate date9. Value1;
185 datalines;

NOTE: Invalid data for enddate in line 186 14-22.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+
186 120 01JAN2000 01JAN2000 13
Id=120 startdate=14610 enddate=. Value1=0 _ERROR_=1 _N_=1
NOTE: Invalid data for enddate in line 187 14-22.
187 120 01JAN2000 01FEB2000 13
Id=120 startdate=14610 enddate=. Value1=0 _ERROR_=1 _N_=2
NOTE: Invalid data for enddate in line 188 14-22.
188 120 01FEB2000 01APR2000 15
Id=120 startdate=14641 enddate=. Value1=0 _ERROR_=1 _N_=3
NOTE: Invalid data for enddate in line 189 14-22.
189 120 01APR2000 01MAY2000 19
Id=120 startdate=14701 enddate=. Value1=0 _ERROR_=1 _N_=4
NOTE: Invalid data for enddate in line 190 14-22.
190 120 01MAY2000 01Dec2000 5
Id=120 startdate=14731 enddate=. Value1=0 _ERROR_=1 _N_=5
NOTE: The data set TEST.MERGE_TEST_1 has 5 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds

 

I would really appreciate if you can tell me the problem. 

 

Thank you. 


Accepted Solutions
Solution
‎10-22-2016 01:30 AM
Respected Advisor
Posts: 3,886

Re: Error for date

You need to use the colon modifier.

 

The : (colon) format modifier enables you to use list input but also to specify an informat after a variable name, whether character or numeric. SAS reads until it encounters a blank column, the defined length of the variable (character only), or the end of the data line, whichever comes first.

 

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1w749t788cgi2n1txpu...

 

data test.Merge_test_1;
  input Id startdate :date9. enddate :date9. Value1;
  datalines;
120 01JAN2000 01JAN2000 13
120 01JAN2000 01FEB2000 13
120 01FEB2000 01APR2000 15
120 01APR2000 01MAY2000 19
120 01MAY2000 01Dec2000 5
;
run;

View solution in original post


All Replies
Solution
‎10-22-2016 01:30 AM
Respected Advisor
Posts: 3,886

Re: Error for date

You need to use the colon modifier.

 

The : (colon) format modifier enables you to use list input but also to specify an informat after a variable name, whether character or numeric. SAS reads until it encounters a blank column, the defined length of the variable (character only), or the end of the data line, whichever comes first.

 

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1w749t788cgi2n1txpu...

 

data test.Merge_test_1;
  input Id startdate :date9. enddate :date9. Value1;
  datalines;
120 01JAN2000 01JAN2000 13
120 01JAN2000 01FEB2000 13
120 01FEB2000 01APR2000 15
120 01APR2000 01MAY2000 19
120 01MAY2000 01Dec2000 5
;
run;
Contributor
Posts: 22

Re: Error for date

Thank you very much for your help as well as the link! It was very helpful.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 226 views
  • 1 like
  • 2 in conversation