BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SasStatistics
Pyrite | Level 9

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: 

SasStatistics_0-1678119135290.png


For some reason, the last column: valid_to_date is empty whereas it should be 2023-01-10. 

Any advice on what is wrong? 

 



1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

Tom_0-1678119538494.png

 

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.

 

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.

Tom_0-1678119538494.png

 

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.

 

 

SasStatistics
Pyrite | Level 9

That was the problem. Time to go home... 😉 
Many thanks. 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 558 views
  • 1 like
  • 2 in conversation