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

Hi to everybody!

 

I'm working with date formats. I've got a nice data set with this but the forma of my dates are for example: 02/11/2016. I need to put first the day, then month and then year. Untill here everything is ok but I would like to put them in this format: 02/NOV/2016 and I can't!

I wrote "Month = put(date,monname3.);" and now I've converted my variable month from number to Words but I am not able to put that in the way I want "02/NOV/2016" "24/FEB/2013", etc.
 

DatePA= left(fecha);
Day = SUBSTR(fechapa,7,2);
Month = SUBSTR(fechapa,5,2);
Year = SUBSTR(fechapa,1,4);
Date = MDY (Month,Day,Year);
Month = put(date,monname3.);
format Date ddmmyy10.;

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Investigate whether the requirements can be a little bit flexible.  It's very easy to come close to what you are asking for:

 

m1 = put(date, date11.);

 

or

 

m2 = put(date, date9.);

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Investigate whether the requirements can be a little bit flexible.  It's very easy to come close to what you are asking for:

 

m1 = put(date, date11.);

 

or

 

m2 = put(date, date9.);

Reeza
Super User

Look at building a custom format, with PROC format. 

Its easier than you think 🙂

 

Proc format;

picture ddmonyy other= "%0d/%b/%Y" (datatype=date);

run;

ballardw
Super User

When dealing with dates it is often easier to actually use a SAS date valued variable an a format. Your request for / in the middle of the date with the month name is uncommon but doable with a custom format.

 

The following code creates a SAS date valued variable from a character variable that I think mimics your fechapa variable.

Then uses the custom format created with proc format to display the date as desired.

NOTE: the case of the letters in the string '%d/%b/%Y' is critical as changing the Y to y will result in a 2 digit year and a %B instead of %b is the full name not the 3-letter abbreviation. The % tells proc format the values are directives and the datatype tells SAS what ranges of values to expect.

data example;
   x='20160425';
   y=input(x,yymmdd8.);
   format y date9.;
run;

proc format library=work;
picture DateSlash  (default=12)
  low-high= '%d/%b/%Y'  ( datatype=date)
;
run;

proc print data=example;
   var y;
   format y dateslash.;
run;

So once you have your Date variable you use the format dateslash as needed. Note, since this is a custom format permanent association of the format means that you should place the format in a location that is always in the FMTSEARCH path OR rerun the proc format as needed.

 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 2877 views
  • 0 likes
  • 4 in conversation