BookmarkSubscribeRSS Feed
Andrewpass
Fluorite | Level 6

Hi All,

 

How could we replace missing mm/yyyy as 99/9999 in sas?

 

Thanks.

3 REPLIES 3
BrunoMueller
SAS Super FREQ

You can make use of format that makes use of the nested format definition.

 

Here is a sample:

proc format;
  value my_mmyys (default=7)
    . = "99/9999"
    other = [mmyys7.]
  ;
run;

data have;
  do someDate = ., "01jan2016"d, "31aug2016"d;
    someDate2 = someDate;
    output;
  end;

  format
    someDate mmyys7.
    someDate2 my_mmyys.
  ;
run;

Bruno

ChrisNZ
Tourmaline | Level 20

Since 99 is not a valid month, you can't replace the missing date with 99/9999.

You can display the missing date as 99/9999 though, as @BrunoMueller showed.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

To what purpose?  If it is to display that in a report, then the simplest option is to have two variables - one a numeric date, and one a character version of that allowing for partials, and missing conversions.  This is what we do for analysis domains, the numeric to perform windowing and such like, and character for listings so it reflects the data.  I would not recommend applying some sort of internal format to the data for two (actually 3) reasons - first anyone who uses SAS knows dates and that . indicates missing - if you try to change that underlying understanding then anyone who uses your code/data has to learn all your specific things.  Secondly it requires a SAS specific thing - formats - to achieve, if your data is going anywhere to another system/format then that will cause further issues for you.  Also, I personally avoid the use of proprietary binary files as much as possible - the 32bit versus 64bit completely destroying any work done previously with catalogs is a very good example of why.  

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1229 views
  • 0 likes
  • 4 in conversation