Help using Base SAS procedures

SAS Date MMYYYY

Accepted Solution Solved
Reply
Regular Contributor
Posts: 173
Accepted Solution

SAS Date MMYYYY

Hello Everyone,

How do I format a numeric field (i.e. 102012) as Oct 2012?

I basically want to show the month (Oct) plus the year (2012).  Is this possible?

Thank you so much for any input! Smiley Happy


Accepted Solutions
Solution
‎10-12-2012 11:29 AM
Regular Contributor
Posts: 173

Re: SAS Date MMYYYY

Hi Ksharp,

Thank you so much for your suggestion!  It worked.  But now I realize I need the result in a different format.

I actually need 02012 as OCT-12.

I modified your code as below and came up withAUG12.  Is it possible to add a '-' between AUG and 12?

Thank you again for your help! Smiley Happy

proc  format ;

picture fmt(default=5)

other='%b%y'(datatype=date);

run;

data _null_;

a=23234;

format a fmt.;

put a= ;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 4,641

Re: SAS Date MMYYYY

Try  fornat  nldateym8.

PG

PG
Super User
Posts: 9,662

Re: SAS Date MMYYYY

You need customize it on your own.

proc  format ;
picture fmt(default=8)
 other='%b%Y'(datatype=date);
run;

data _null_;
a=23234;
format a fmt.;
put a= ;
run;

Ksharp

Solution
‎10-12-2012 11:29 AM
Regular Contributor
Posts: 173

Re: SAS Date MMYYYY

Hi Ksharp,

Thank you so much for your suggestion!  It worked.  But now I realize I need the result in a different format.

I actually need 02012 as OCT-12.

I modified your code as below and came up withAUG12.  Is it possible to add a '-' between AUG and 12?

Thank you again for your help! Smiley Happy

proc  format ;

picture fmt(default=5)

other='%b%y'(datatype=date);

run;

data _null_;

a=23234;

format a fmt.;

put a= ;

run;

SAS Employee
Posts: 2

Re: SAS Date MMYYYY

Hi Kevin, If you have 9.3 you could use a format based on a function. Regards Jeroen. proc fcmp outlib=work.functions.smd;   function MonYear(date) $ 8; month = floor(date / 10000);       year  = date - (month * 10000); if month < 1 or month > 12 then do; month = 1; end; return (catx(' ', put(mdy(month, 1, year), monname3.), put(year, 4.)));   endsub; run; /* Make the function available to SAS. */ options cmplib=(work.functions); /* Create a format using the function created by the FCMP procedure. */ proc format;   value MonYear         other=[MonYear()]; run; /* Use the format in a SAS program.  */ data test;       input testdate;       datalines; 12011 022012 122013 ; run; proc print data=test; format testdate MonYear.; run;

Regular Contributor
Posts: 173

Re: SAS Date MMYYYY

Thank you, Jeroen.  Unfortunately we use 9.1.  Thank you for your response Smiley Happy

Kevin


Super User
Posts: 9,662

Re: SAS Date MMYYYY

Easy.

proc  format ;
picture fmt(default=8)
 other='%b-%0y'(datatype=date);
run;

data _null_;
a=18234;
format a fmt.;
put a= ;
run;

Ksharp

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 2186 views
  • 6 likes
  • 4 in conversation