How do I change the date from e.g. 2-Nov-07 to 02-Nov-1907 so that all the dates in the column can be in the new format (dd-mmm-yyyy)
I have a rather big data set and there are a lot on dates similar to the one above I need to change
For these two formats, the DATE11 informat should work:
birthday_num = input(birthday,date11.);
format birthday_num yymmdd10.;
Use any date format to your liking in the FORMAT statement.
A SAS date is a number counting the days from 1960-01-01, and how it is displayed is controlled by the format used. So, if your variable is a SAS date and not a character variable, all you need to do is change the format with PROC DATASETS, which will only change the dataset header.
Inspect your variable(s) either by right-clicking on the column in a table viewer, or run PROC CONTENTS.
Please read the docs about dates in sas: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n0c9zxlm4e6m7tn1vrn76c98zw66.ht...
If your dates are stored a strings, fixing this will automatically fix your issue. You need to show an excerpt of the data, if you need more assistance.
It seems(!) you have dates stored as character, which is sub-optimal, to say the least.
If this is really the case (run PROC CONTENTS!), we need to see comprehensive examples of the different styles, so we can suggest how to make usable SAS dates out of the character data.
My birthday was not set as a string
Ran the proc contents, attached an image below
If birthday is the variable we are talking about, then it is character (see the list).
For the other dates (date, anniv, prevdate), they are already SAS dates, so only a change of format is needed to change how they are displayed.
So what is it that you need to do?
I need to change dates inside the columns that are like this "2-oct-07" to this 02-oct-1907
WHICH COLUMNS???
Name them!!! And show values which need to be corrected.
The birthday column, some are in the format I want which is -> 02-Oct-1987 but some are 2-oct-07.
Sorry, just started SAS and I'm not good in all these
For these two formats, the DATE11 informat should work:
birthday_num = input(birthday,date11.);
format birthday_num yymmdd10.;
Use any date format to your liking in the FORMAT statement.
Welcome to the Y2K problem.
Read the field as character and add your own logic to convert it to dates.
You can check for the values that only have years. You could just give set those to Jan first.
Then compare the birthyear to the award year and when they won before they were born adjust the dob by 100 years.
filename csv 'c:\downloads\oscar.csv';
data want;
infile csv firstobs=2 dsd truncover ;
length ID $20 Birthplace $40 Birthday $11 AwardYear 8 Award $30 biourl $200 Movie $100 Person $50 ;
input id -- person;
if length(birthday)=4 then dob=mdy(1,1,input(birthday,4.));
else dob = input(birthday,date11.);
format dob date9.;
if AwardYear - year(dob) < 0 then dob=intnx('year',dob,-100,'s');
age = AwardYear - year(dob);
run;
proc print data=want(drop=biourl);
run;
How do you know if 26-AUG-22 is 1922 or 2022?
@Tom @Kurt_Bremser 😄Thanks everyone! Problem solved!
@Reeza my prof gave a hint haha
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.