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.
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.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.