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

I know there is a simple solution but I am having trouble finding it here..So if someone know where the solution is, can you please just post the link.

 

I am trying to change the date format from '01JAN2017' to '0116'.   The '01JAN2017' field is currently in numeric date9. format.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why would you want the value in MMYY order? That will not sort properly and would be very confusing. Why YYMM?

Do you want a string?

str = substr(put(date,ddmmyy6.),3,4);

A number?

numb = month(date)+100 + year(date)-2000 ;
format numb z4. ;

If a number do want to store the actual date and just attach a format?

proc format;
 picture mydt other='%0m%0y' (datatype=date);
run;
....
format date mydt4.;

 

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Change the format on this variable to MMDDYY4.

--
Paige Miller
ballardw
Super User

@tobyfarms wrote:

I know there is a simple solution but I am having trouble finding it here..So if someone know where the solution is, can you please just post the link.

 

I am trying to change the date format from '01JAN2017' to '0116'.   The '01JAN2017' field is currently in numeric date9. format.

 

Thank you.


Where does the 16 come from for 01Jan2017? If isn't a month number, a day number or any reasonable year value?

If you mean 0101 for 01Jan2017 then @PaigeMiller is correct.

tobyfarms
Fluorite | Level 6

@ballardw Sorry that was a mistake. I meant to have '0117', capturing the monthYear.  

PBsas
Obsidian | Level 7
data want;
format date mmyyn4.;
date='01jan2017'd;
run;

Try this

 

mkeintz
PROC Star

How about 2-digit year first, then 2-digit month?  If so, you can use the yymmdd format, truncated to 4 characters.

 

data _null_;

  d='27sep2017'd;

  put d=yymmdd4.;

run;

 

 

editted additon:  I didn't see a MMYY format, but @PBsas did.  So you can ignore the below:

 

If you really need MMYY, I don't see a MMYY format.  But you can make your own, using the PICTURE statement and the DATATYPE option, as in:

 

 

proc format;
  picture myformat (default=4)
    low-high = '%0m%0y' (datatype=date);
run;

data _null_;
  d=today();
  put d=myformat. ;
run ;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

Why would you want the value in MMYY order? That will not sort properly and would be very confusing. Why YYMM?

Do you want a string?

str = substr(put(date,ddmmyy6.),3,4);

A number?

numb = month(date)+100 + year(date)-2000 ;
format numb z4. ;

If a number do want to store the actual date and just attach a format?

proc format;
 picture mydt other='%0m%0y' (datatype=date);
run;
....
format date mydt4.;

 

tobyfarms
Fluorite | Level 6
The Substr function worked for what I am trying to achieve in my coding. This populate the 2-digit month and 2 digit year from my current date format. Thanks @Tom
ShiroAmada
Lapis Lazuli | Level 10

Try this...

 

data _null_;
  today=today();
format today MMYYN4.;
PUT TODAY;
run;

Hope this helps.

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