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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

2 REPLIES 2
Patrick
Opal | Level 21

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;
Leon_Seungmin
Obsidian | Level 7
Thank you very much for your help as well as the link! It was very helpful.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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