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
data want;
set dat;
date=mdy(month,1,year);
format date monyy7.;
run;
data want;
set dat;
date=mdy(month,1,year);
format date monyy7.;
run;
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.
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!
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.