- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have; input d date14.; datalines; 20may2021 5:15 ; run; data want; input d $ date9.; datalines; 20may2021 ; run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have; input d date14.; datalines; 20may2021 5:15 ; run; data want; input d $ date9.; datalines; 20may2021 ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please state a clear question that you want to have an answer to.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;