BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gick
Pyrite | Level 9
data dat;
length month 8 year 8 ;
input month year;
datalines;
2         2020
5         1992
10       2005
12       2012
4 1994
;
Data dat;
set dat;
format date DDMM10. mois1 $ 2. annee1 $4.;
mois1=put(month, 2.);
annee1=put(year, 4.);
date=mdy(input(mois1,DDMM10.),input(annee1,DDMM10.));
run;

Hi,

I have 2 numeric format variables month and year. The data is presented in the set dat. I want to calculate the date variable in date format taking into account only the month and the year, for example "Feb2020" or "02/2020".

here is the code i made but i find the dots(.). I don't know why it doesn't work.

I'm open to other suggestions too.

Thank you
Gick

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set dat;
    date=mdy(month,1,year);
    format date monyy7.;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set dat;
    date=mdy(month,1,year);
    format date monyy7.;
run;
--
Paige Miller
Tom
Super User Tom
Super User

The reason it does not work is pretty clearly explained by the error messages in the SAS log.

1035  Data dat;
1036  set dat;
1037  format date DDMM10. mois1 $ 2. annee1 $4.;
                  -------
                  484
NOTE 484-185: Format DDMM was not found or could not be loaded.

1038  mois1=put(month, 2.);
1039  annee1=put(year, 4.);
1040  date=mdy(input(mois1,DDMM10.),input(annee1,DDMM10.));
                           -------               -------
                           485                   485
           ---
           71
NOTE 485-185: Informat DDMM was not found or could not be loaded.

ERROR 71-185: The MDY function call does not have enough arguments.

1041  run;

There is no format named DDMM nor any informat with that name either.

The MDY() function requires three arguments, Month, Day and Year.

Your dataset has Month and Year so you just need to pick some day in that month to be able to generate a date value.  Normally people use 1.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 498 views
  • 1 like
  • 3 in conversation