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

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

1 ACCEPTED SOLUTION

Accepted Solutions
KevinC_
Fluorite | Level 6

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

6 REPLIES 6
PGStats
Opal | Level 21

Try  fornat  nldateym8.

PG

PG
Ksharp
Super User

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

KevinC_
Fluorite | Level 6

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;

Jeroen
SAS Employee

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;

KevinC_
Fluorite | Level 6

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

Kevin


Ksharp
Super User

Easy.

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

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

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 7281 views
  • 6 likes
  • 4 in conversation