Hi SAS expert, I have a date in the format of yyyymm, how to format in SAS date ?
yyyymm
196507
196508
196509
196510
196511
196512
196601
196602
196603
196604
196605
Thanks
The informat instructs SAS how to read a text string for conversion to a SAS Date value, the format instructs SAS how to print the SAS Date value.
The SAS Date value created will be the first of the month. You can use another format like DATE9. to also print the date.
data sample;
attrib my_dt length=8 informat=yymmn6. format=yymmn6.;
input my_dt;
datalines;
196507
196508
196509
196510
196511
196512
196601
196602
196603
196604
196605
;
proc print data=sample;
run;
proc print data=sample;
format my_dt date9.;
run;
Use the INTNX function:
date1 = intnx('month',yyyymm,1,'b');
date2 = intnx('month',yyyymm,1,'e');
format date1 date2 yymmddn8.;
Attaching a format to an existing variable does not change the values stored in the variable.
So if you have a numeric variable that has a value like 196,507 and tell SAS to use the YYMMN6. format to display it then it will treat that number as the number of days since 1960 so that number would mean 06JAN2498.
If you want to convert the number 196,507 to the date 01JUL1965 then you need to convert it. Since INFORMATs convert text to numbers you first need to use a FORMAT to convert the number to a text string.
data syy.data2;
set syy.data1;
yyyymm = input(put(yyyymm,z6.),yymmn6.);
format yyyymm date9.;
run;
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.