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


data l;
input id$ 1-12;
id1=input(id,date9.);
id2=input(id,date9.);
format id1 date.;
format id2 date9.;
cards;
15-sep-10
run;
proc print;
run;

i want the out put in dd-mon-yy format what is the format i sould use to get the output like this.

id1

15-sep-10 

1 ACCEPTED SOLUTION

Accepted Solutions
nathan_owens
Obsidian | Level 7

The easiest way to accomplish this is to build your own picture format using directives:

%0d - gives you the day of the month, with a leading zero if a single digit

%b - gives you the month abbreviation

%0y - gives you the 2 digit year with a leading zero if a single digit.  For a 4 digit year you can use the date11. format.

proc format ;

     picture date9d other = '%0d-%b-%0y'( datatype= date ) ;

run;

format id1 date9d.;

View solution in original post

8 REPLIES 8
ieva
Pyrite | Level 9

Hi,

The closest format I could find was ddmmyyd10. It outputs date in form 15-09-10. Maybe it helps.

Ieva

art297
Opal | Level 21

if you can live with a 4 digit year, you can use date11.  Otherwise, you may have to roll your own using proc format.

Peter_C
Rhodochrosite | Level 12

As Art suggests, the closest is DATE11. followed by writing your own with something like

proc format ;

  picture date9x other = '%0d-%b-%0y'( datatype= date ) ;

  picture date9t other = '%0d-%b-%0y'( datatype= datetime ) ;

run ;

* testing ;

%put %sysfunc( today(), date9x ) ;

%put from datetime value,  %sysfunc( datetime(), date9t ) ;

which report to the log like

5 %put %sysfunc( today(), date9x ) ;

28-NOV-11

6 %put from datetime value, %sysfunc( datetime(), date9t ) ;

from datetime value, 28-NOV-11

SanjeevaReddyEeda
Fluorite | Level 6

%LET date=%SYSFUNC( PUTN( %SYSFUNC( DATE() ),date11. ));

chang_y_chung_hotmail_com
Obsidian | Level 7

If you *really* want to have the three-letter month name lower-cased, then here is one way. hth.

   /* create a custom date format, datedash,
      for the date range, 1jan2010 - 31dec2030 */
   data f;
      retain fmtname "datedash";
      drop d;
      do d = '1jan2010'd to '31dec2030'd;
         start = d;
         label = catx('-', put(day(d), z2.0),
            lowcase(put(d, monname3.)),
            put(d, year2.));
         output;
      end;
      hlo = "other";
      label = repeat("*",9-1);
      output;
   run;
   proc format cntlin=f;
   run;


   /* check */
   data _null_;
      do d = '31dec2009'd, '1sep2010'd,
         '15dec2015'd, '31dec2030'd, '1jan2031'd;
         put d= :datedash.;
      end;
   run;
   /* on log
   d=*********
   d=01-sep-10
   d=15-dec-15
   d=31-dec-30
   d=*********
   */

nathan_owens
Obsidian | Level 7

The easiest way to accomplish this is to build your own picture format using directives:

%0d - gives you the day of the month, with a leading zero if a single digit

%b - gives you the month abbreviation

%0y - gives you the 2 digit year with a leading zero if a single digit.  For a 4 digit year you can use the date11. format.

proc format ;

     picture date9d other = '%0d-%b-%0y'( datatype= date ) ;

run;

format id1 date9d.;

NavaneethaKSS
Calcite | Level 5
data _null_;
   monyy = &runasofdate;
   date1 =input(put(monyy,10.),yymmdd10.);
   put date1=date11.;
  call symput('date1',STRIP(date1));
run;
%PUT &date1;

Data _null_;
a = &date1;
dt1 =put (a, date11.);
put dt1;
run_date=((substr(strip(dt1),1,7)))||(substr(strip(dt1),10,2));
call symput('run_date',STRIP(run_date));

run;

%PUT &run_date;

NavaneethaKSS
Calcite | Level 5
data _null_;
   monyy = &runasofdate;
   date1 =input(put(monyy,10.),yymmdd10.);
   put date1=date11.;
  call symput('date1',STRIP(date1));
run;
%PUT &date1;

Data _null_;
a = &date1;
dt1 =put (a, date11.);
put dt1;
run_date=((substr(strip(dt1),1,7)))||(substr(strip(dt1),10,2));
call symput('run_date',STRIP(run_date));
run;
%let run_date1="'&run_date'd";
%let run_date = %sysfunc( dequote(&run_date1)) ;
%PUT &run_date;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 36783 views
  • 1 like
  • 8 in conversation