I am trying to use 2 fields that I am pulling in with the format 200810 (yyyymm) to calculate the months between these values. The data type in the data set for this field is text. Please let me know how I can calculate the number of months between 2 dates in this format.
I am still new to SAS and so any help will be greatly appreciated. Thanks.
Message was edited by: Caesar
You will want to convert your partial date text-string to a SAS numeric variable DATE value (days since 1/1/1960). In a DATA step, you can take your partial string and concatenate a "01" to complete your date string in format "yyyymmdd", and use the ANYDTDTE. or another SAS date-related INFORMAT to derive your SAS numeric DATE variable.
Given your post, perform this task for each of your two partial-date text-string data values, and then use the INTCK function to derive a variable that will represent the months between your two dates.
The SAS support website http://support.sas.com/ has SAS product documentation and technical (user community, SUGI/SGF) papers on this topic. I have provided one example below for your reference.
The YYMMN informat would allow you to use the INPUT statement to convert your character string to a SAS date value. This informat will use 01 for the date value for any given year/month.
Then, you could either divide to get the number of months (after your subtraction) or you could just use the INTCK function to get the number of months.
See the program below for some possible logic. Of course, you could also substring out the year and month and make your own date value if you wanted some other day to be used (like 15 or 20) instead of 01.
** make some character strings;
** which are really yyyymm values;
input ordered $ shipped $;
proc print data=makedata;
title 'Dates as Character Strings';
** with this INFORMAT, SAS uses 01 as the ;
** day value for the date;
dt_ord = input(ordered,yymmn6.);
dt_shp = input(shipped,yymmn6.);