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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 913 views
  • 3 likes
  • 4 in conversation