BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

How to convert a number into date, say the no is 22625 which I want to show as 11Dec2021, I read the doc but couldnt get it. Thanks.

1 REPLY 1
ballardw
Super User

I think all you need to do is apply a DATE9. format. If you do this as part of a data step then the format is now the default display format.

 

data example;
   x=22625;
   format x date9. ;
run;

You can assign a different format for specific uses:

Title "Default format assigned";
proc print data=example;
run;

Title "Override default format in procedure";
proc print data=example;
   format x yymmdd10.;
run;
title;

SAS formats are rules for how to display any given value(s). Note that the the name of the format ends in a dot, or would have a dot where decimals would occur. In the following example the number will be displayed with at most 12 characters including a decimal point and 2 decimals, which here forces zeroes after the decimal.

Proc print data=example;
    format x f12.2;
run;

Formats are a very powerful tool in SAS as groups created by formats are used by most analysis, graphing and reporting procedures. So if you have a lot of date values and want to know how many values are in each year you could use Proc freq and a format that only displays years:

Proc freq data=yourdataset;
   tables datevariable;
   format datevariable year4. ;
run;

Or pick a format that only displays year and month to get the count in each calendar month.

 

Since you can create your own formats with Proc Format the are very few limits on grouping with formats. Plus a few procedures can use special Multiple label formats so that one format could create things like age group 1 to 18, 1 to 6,7 to 12, 13 to 18, 1 to 3, 4 to 6, 7 to 9, 10 to 13, 10 to 18, for example with a single format. Again only Procs Tabulate, Report, Means and Summary will use these but can be very helpful.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 430 views
  • 3 likes
  • 2 in conversation