- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all:
If I have a data like 2014-06-09, please advise me how to input it from a text file into date format as in SAS file.
Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input char_date : $20. fmt : $20.;
num_char=inputn(char_date,fmt);
format num_char date9.;
cards;
12-08-2015 DDMMYY12.
12/8/2016 MMDDYY12.
05/25/2015 MMDDYY12.
;
run;
proc print;run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
do you mean
input date yymmdd10.;
format date yymmdd10.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Using the Informat YYMMDD10. ought to work.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What about 12/9/2018?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
do you have a mix of date values with some being yymmdd ,yymmdd and ddmmyy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ybz12003 wrote:
What about 12/9/2018?
That is actually ambiguous as we cannot tell from the given value which is the month and which is the day.
There are a whole slew of date informats
mmddyy
ddmmyy
yymmdd
date
If your data in provided external file has varied date formats there is even ANYDTDTE. but that guesses about some sorts of values and they may not match your need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ybz12003 wrote:
What about 12/9/2018?
Do a google search for "sas date informats", and then select an informat from the documentation that suits your input data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't have a mix date format, but I do have the different date format due to the source coming from the different places. For example,
A city's date format is 12-08-2015
B city's date format is 12/8/2016
C city's date format is 05/25/2015
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Does your source data looks like
A city's date format is 12-08-2015
B city's date format is 12/8/2016
C city's date format is 05/25/2015
If yes, let us know how you want to read it? Should i assume
A city's date format is --one char variable
12-08-2015--date variable
?
would be clear to let know what you want
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A city's date format is 12-08-2015
B city's date format is 12/8/2016
C city's date format is 05/25/2015
As pointed out above, this is ambiguous. Can you clarify if A and B are month-day-year, or day-month-year?
Also, the different delimiters are not really a problem here, the format should read the dates properly even if the delimiters change.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A city's date format is 12-08-2015 DD-MM-YYYY
B city's date format is 12/8/2016 MM/D/YYYY
C city's date format is 05/25/2015 MM/DD/YYYY
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
After you have identified in your own mind which city uses which convention as far as month-day-year or day-month-year, you need to write code so that the city will be read via the proper informat, which is MMDDYY. or DDMMYY. or possibly others
Maybe something like this
data want;
input chardate $10. othervariables ... ;
if city='A' then date=input(chardate,ddmmyy10.);
else if city in ("B","C") then date=input(chardate,mmddyy10.);
format date date7.;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input char_date : $20. fmt : $20.;
num_char=inputn(char_date,fmt);
format num_char date9.;
cards;
12-08-2015 DDMMYY12.
12/8/2016 MMDDYY12.
05/25/2015 MMDDYY12.
;
run;
proc print;run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for all of your great suggestion. It helps! 🙂