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

data have; input d  date14.; datalines; 20may2021 5:15 ; run; data want; input d $ date9.; datalines; 20may2021 ; run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

First, note that dates should be numeric, not character.  So this DATA step would need to change:

data want; 
input d $ date9.; 
datalines; 
20may2021
 ;

Get rid of the dollar sign and apply a format:

data want; 
input d date9.;
format d date9.; 
datalines; 
20may2021
 ;

Second, note that you don't have to read in everything on the line.  You can pick and choose.  So this DATA step still works when the data contains the time and you only want the date:

 

data want; 
input d date9.;
format d date9.; 
datalines; 
20may2021 05:15
 ;

View solution in original post

5 REPLIES 5
aanan1417
Quartz | Level 8

data have; input d date14.; datalines; 20may2021 5:15 ; run; data want; input d $ date9.; datalines; 20may2021 ; run;

PaigeMiller
Diamond | Level 26

Please state a clear question that you want to have an answer to.

--
Paige Miller
Sajid01
Meteorite | Level 14

Hello @aanan1417 
Try this

data have (drop=t);
 informat d date9. t time5.;
 format d date9.;
	input d t ;
	datalines;
20may2021 5:15 
;
run;

The output will be as follows

may26.PNG

aanan1417
Quartz | Level 8
both date are under same variable . and i need number of days
Astounding
PROC Star

First, note that dates should be numeric, not character.  So this DATA step would need to change:

data want; 
input d $ date9.; 
datalines; 
20may2021
 ;

Get rid of the dollar sign and apply a format:

data want; 
input d date9.;
format d date9.; 
datalines; 
20may2021
 ;

Second, note that you don't have to read in everything on the line.  You can pick and choose.  So this DATA step still works when the data contains the time and you only want the date:

 

data want; 
input d date9.;
format d date9.; 
datalines; 
20may2021 05:15
 ;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 532 views
  • 3 likes
  • 4 in conversation