If you make a PICTURE format and use a DATE "directive", you can insert the hyphens into any kind of date format you want to design. Some of the SAS formats allow you to specify a separator, but the DATE7 and DATE9 formats don't fall into that category.
In this program, I have a PROC FORMAT that sets up the special date PICTURE format and then my PROC PRINT uses the format -- and shows some other formats by way of comparison.
You can seperate the Day ,Month and Year from the DATE varaible by using the functions like PUT,SUBSTR,YEAR.
Convert the DATE varaible from numeric to Character Data Type by using PUT function ,Beacuse DATE varaible is a Numeric Data Type.After seperating the Day,Month and Year from the DATE varaible.
You can concatenate the Day,Month,Year and hypen symbol ('-') by using the CAT function or Concatente symbol (||).
input id_no name $ st_date date9.;
date = st_date;
new1 = put(date,date.);
month = substr(new1,3,3);
day = substr(new1,1,2);
year = year(st_date);
new_date = compress(day||'-'||month||'-'||year);
1 Venu 15NOV2005
2 Prem 23DEC2005
3 Tyler 25JAN2006
4 Clark 28JAN2006
5 Sam 02MAR2006
proc print data = testdates;
var day month year new_date;
Converting dates to strings and substringing is a poor idea IMHO. There are many very good functions in SAS that allow parsing out the date elements.
The Day() and Year() functions will extract the values, and the month name can be added by using the MonName. format.
Having said that, the most elegant solution remains the one that creates a custom picture format. As usual, the Queen of ODS demonstrates that there is little she can't do to give you data as you like it.
P.S. again for forum support: and the dictionary doesn't know ODS either. Could the dictionary be loaded with the procedure names and standard SAS syntax?
I agree with you in terms that DAY, MONTH, YEAR and SUBSTR etc. is generally not the most efficient way creating these types of display formats and I would generally use Cynthia's PICTURE format (very under-used in my experience!).
However, if you work in clinical trials as I do, you get plenty of partial dates (day or day and month unknown) so to list this data you often have to create character equivalents of the form: "XX-JUN-2007" or similar.
In this case, I would use the character functions.