data dt;
length date$ 15;
input date;
cards;
2014-may-31
2015-06-31`
2014-07-14
2021-jun-21
;
run;
I need dates like
2014-may-31
2015-jun-31
2014-Aug-14
2021-jun-21
is there anyway to get dates like this. Can anyone help me to do this job
I'm not completely sure what you need. Do you want a formatted SAS date or a standardized character date? Here are some results, immediately below. Are any of these columns what you need? The program that produced them is below. By the way, there is no 31st day of June, so SAS is producing a missing value for 2015-06-31.
data dt;
length Input_Date $15;
FORMAT SAS_Date DATE11.;
input Input_Date $;
SAS_Date = INPUT(Input_Date, ANYDTDTE11.);
Formatted_Date = CATS(SUBSTR(vvalue(SAS_Date), 8, 4), LOWCASE(SUBSTR(vvalue(SAS_Date), 3, 5)), SUBSTR(vvalue(SAS_Date), 1, 2));
cards;
2014-may-31
2015-06-31
2014-07-14
2021-jun-21
;
run;
Jim
As far as I know, there is no preprogrammed format YYYY-mon-dd. You could certainly create your own custom format in PROC FORMAT.
You can read your data as follows:
data dt;
input date :anydtdte12.;
format date date9.;
cards;
2014-may-31
2015-06-30
2014-07-14
2021-jun-21
;
Please note that I have changed your data line 2015-06-31` to remove the unnecessary character, and because there are not 31 days in June.
This mostly works:
proc format; picture customdate (default=11) low-high = '%Y-%3B-%0d' ( datatype=date); run; data dt; informat date anydtdte.; format date customdate.; input date; cards; 2014-may-31 2015-06-31` 2014-07-14 2021-jun-21 ; run;
Your desired appearance is not a standard date layout from what I see.
However, June NEVER has 31 days so your value of 2015-06-31 is an invalid date and you need to decide what value it should be.
When you import your date, you can specify an informat. This tells SAS what format the data should be read in as. The format then controls how it's displayed.
To fix it while reading in: (Note that June 31 is an invalid date so SAS will not create that date).
data dt;
informat date anydtdte.;
format date date11.;
input date;
cards;
2014-may-31
2015-06-31
2014-07-14
2021-jun-21
;
run;
proc print data =dt;
run;
If you need to convert it after the fact, this is what you'd use:
data want;
set dt;
date_num = input(date, anydtdte12.);
format date_num date11.;
run;
proc print data=want;
run;
@sasuser123123 wrote:
data dt;
length date$ 15;
input date;
cards;
2014-may-31
2015-06-31`
2014-07-14
2021-jun-21
;
run;
I need dates like
2014-may-312015-jun-31
2014-Aug-14
2021-jun-21
is there anyway to get dates like this. Can anyone help me to do this job
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.