I write the following SAS code:
data customer_from_to_table;
LENGTH customer_id 8 segment_generation $ 100 segment_belonging $ 1 valid_from_date 8 valid_to_date 8;
input customer_id segment_generation $ segment_belonging $ valid_from_date :yymmdd10. valid_to_date :yymmdd10.;
format valid_from_date yymmdd10. valid_to_date yymmdd10.;
datalines;
111 segment_generation_1 A 2023-01-01 2023-01-10
;
run;
and I get the following result:
For some reason, the last column: valid_to_date is empty whereas it should be 2023-01-10.
Any advice on what is wrong?
Your code works for me.
I suspect that one of the three characters past the end of the data on your data line is not actually a space. Notice how this FORUM's editor is highlighting that area in yellow.
If I replace it with something I can see
data customer_from_to_table;
LENGTH customer_id 8 segment_generation $ 100 segment_belonging $ 1 valid_from_date 8 valid_to_date 8;
input customer_id segment_generation $ segment_belonging $ valid_from_date :yymmdd10. valid_to_date :yymmdd10.;
format valid_from_date yymmdd10. valid_to_date yymmdd10.;
datalines;
111 segment_generation_1 A 2023-01-01 2023-01-10|
;
I get an error:
6673 data customer_from_to_table; 6674 LENGTH customer_id 8 segment_generation $ 100 segment_belonging $ 1 valid_from_date 8 valid_to_date 8; 6675 input customer_id segment_generation $ segment_belonging $ valid_from_date :yymmdd10. valid_to_date :yymmdd10.; 6676 format valid_from_date yymmdd10. valid_to_date yymmdd10.; 6677 datalines; NOTE: Invalid data for valid_to_date in line 6678 39-49. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 6678 111 segment_generation_1 A 2023-01-01 2023-01-10| customer_id=111 segment_generation=segment_generation_1 segment_belonging=A valid_from_date=2023-01-01 valid_to_date=. _ERROR_=1 _N_=1 NOTE: The data set WORK.CUSTOMER_FROM_TO_TABLE has 1 observations and 5 variables.
Your code works for me.
I suspect that one of the three characters past the end of the data on your data line is not actually a space. Notice how this FORUM's editor is highlighting that area in yellow.
If I replace it with something I can see
data customer_from_to_table;
LENGTH customer_id 8 segment_generation $ 100 segment_belonging $ 1 valid_from_date 8 valid_to_date 8;
input customer_id segment_generation $ segment_belonging $ valid_from_date :yymmdd10. valid_to_date :yymmdd10.;
format valid_from_date yymmdd10. valid_to_date yymmdd10.;
datalines;
111 segment_generation_1 A 2023-01-01 2023-01-10|
;
I get an error:
6673 data customer_from_to_table; 6674 LENGTH customer_id 8 segment_generation $ 100 segment_belonging $ 1 valid_from_date 8 valid_to_date 8; 6675 input customer_id segment_generation $ segment_belonging $ valid_from_date :yymmdd10. valid_to_date :yymmdd10.; 6676 format valid_from_date yymmdd10. valid_to_date yymmdd10.; 6677 datalines; NOTE: Invalid data for valid_to_date in line 6678 39-49. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 6678 111 segment_generation_1 A 2023-01-01 2023-01-10| customer_id=111 segment_generation=segment_generation_1 segment_belonging=A valid_from_date=2023-01-01 valid_to_date=. _ERROR_=1 _N_=1 NOTE: The data set WORK.CUSTOMER_FROM_TO_TABLE has 1 observations and 5 variables.
That was the problem. Time to go home... 😉
Many thanks.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.