Function :MDY

 For the situations where you  only have month, day , and year values but do not have a SAS Date, the MDY functon can create a SAS date value, given the value for the month, day , and year .Kindly find a detailed example on how this is made possible in SAS


Purpose:  To create a SAS Date from the month, day and year.

Sytax: MDY(month, day, year)

             month is a numeric variable or constant representing the month of the year (a number               from 1 to 12 ).

              day  is a numeric variable or constant representing  the day of the month (a number                  from 1 to 31 ).

             year is a numeric variable or constant representing the year.


Values of the month, day and time that do not define a valid date result in a missing value and an error message is written  to the SAS log.

          

Examples
For these examples, M = 11, D = 15, Y = 2003. 

Function                                              Returns       

 MDY(M,D,Y)                                                   16024 (15NOV2003 – formatted value)

MDY(10,21,1980) 
MDY(1,1,1950) 
MDY(13,01,2003)

              7599 (21OCT1980 – formatted value)
              -3652 (01JAN1950 – formatted value)
              numeric missing value                                       

  

Creating a SAS date value from separate variables
representing the day, month, and year of the date


***Primary function: MDY;

data funnydate;

input @1 Month 2.

@7 Year 4.

@13 Day 2.;

Date = mdy(Month,Day,Year);

format Date mmddyy10.;

datalines;

05    2000  25

11    2001  02

; 

title "Listing of FUNNYDATE";

proc print data=funnydate noobs;

run;

Explanation
Here the values for month, day, and year were not in a form where any of the standard date
informats could be used. Therefore, the day, month, and year values were read into separate
variables and the MDY function was used to create a SAS date. See the following listing:














Comments

Popular posts from this blog

UPCASE, LOWCASE & PROPCASE