BookmarkSubscribeRSS Feed
_maldini_
Barite | Level 11

I'm trying to better understand using the DATALINES statement so that I can use it to quickly test functions, etc. while working on a SAS project. I want to be able to include LENGTH, INFORMATS and FORMATS.

 

The following code produces a few errors:

	DATA test;
	INPUT 
		date1 : mmddyy8.
		date2 : mmddyy10.
		date3 : mdyampm25.2;
	DATALINES; 
	6/6/11 4/4/2012 03/26/12 12:58 AM
	7/6/11 3/4/2012 10/26/12 10:58 AM
	;
	FORMAT date1 date2 date3 datetime9.;
	RUN;

I am getting an "invalid data" warning at each row for date1: "NOTE: Invalid data for date1 in line 62 1-7."

Also, the FORMAT statement is producing an error.

 

Is there a better approach to the one I'm using here? 

 

 

Thanks for your assistance.

 

4 REPLIES 4
data_null__
Jade | Level 19

You have a TAB in your data lines you can use INFILE statement option to remove it.  Also your FORMAT statement cannot come after datalines statement. Finally and I think this is it you need & INFORMAT modified for date3 to read embedded blanks.

 

DATA test;
   infile datalines expandtabs;
	INPUT 
		date1 : mmddyy10.
		date2 : mmddyy10.
		date3 & mdyampm25.2;
	FORMAT date1 date2 date3 datetime9.;
   DATALINES; 
   6/6/11 4/4/2012 03/26/12 12:58 AM
   7/6/11 3/4/2012 10/26/12 10:58 AM
;;;;
	RUN;
proc print;
   run;
_maldini_
Barite | Level 11

@data_null__ Thanks for your help here.

 

The embedded blanks are the spaces between the date and time? And between the last digit of the time and AM/PM?

 

I can I determine, going forward, whether an informat accounts for those blanks, or whether I need the "&"? What exactly does the "&" do?

 

Thanks!

Haikuo
Onyx | Level 15

Similar to what @data_null__'s suggestion, only add different format to help keeping time part information:

DATA test;
infile datalines TRUNCOVER EXPANDTABS ;
	INPUT 
		date1 : mmddyy10.
		date2 : mmddyy10.
		date3 : & mdyampm25.2;
FORMAT date1 date2 DATE9.
        date3 dateAMPM25.2;

	DATALINES; 
6/6/11 4/4/2012 03/26/12 12:58 AM
7/6/11 3/4/2012 10/26/12 10:58 AM
	;
	RUN;
PGStats
Opal | Level 21

One more thing, if you want to save typing a line of code. You never need a RUN statement after a datalines (or cards) block. Execution starts as soon as the block ends.

PG

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
  • 4 replies
  • 1307 views
  • 3 likes
  • 4 in conversation