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.
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.;
Change the format on this variable to MMDDYY4.
@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.
@ballardw Sorry that was a mistake. I meant to have '0117', capturing the monthYear.
data want;
format date mmyyn4.;
date='01jan2017'd;
run;
Try this
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 ;
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.;
Try this...
data _null_;
today=today();
format today MMYYN4.;
PUT TODAY;
run;
Hope this helps.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.