Help using Base SAS procedures

Reg:Date in DD-MMM-YY

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 140
Accepted Solution

Reg:Date in DD-MMM-YY


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 


Accepted Solutions
Solution
Monday
Occasional Contributor
Posts: 12

Re: Reg:Date in DD-MMM-YY

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


All Replies
Frequent Contributor
Posts: 82

Reg:Date in DD-MMM-YY

Hi,

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

Ieva

PROC Star
Posts: 7,360

Reg:Date in DD-MMM-YY

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

Valued Guide
Posts: 2,174

Re: Reg:Date in DD-MMM-YY

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

Occasional Contributor
Posts: 5

Reg:Date in DD-MMM-YY

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

Regular Contributor
Posts: 241

Re: Reg:Date in DD-MMM-YY

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=*********
   */

Solution
Monday
Occasional Contributor
Posts: 12

Re: Reg:Date in DD-MMM-YY

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.;

New Contributor
Posts: 2

Re: Reg:Date in DD-MMM-YY

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;

New Contributor
Posts: 2

Re: Reg:Date in DD-MMM-YY

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 10784 views
  • 0 likes
  • 8 in conversation