Hi All,
I get a dataset from a Sharepoint list and the date value is date and time.
I use the below to convert to a yymmdd and format as mmmyy
DefinedPeriod=INPUT(PUT(Date ,8.),YYMMDD8.);format DefinedPeriod monyy7.;
However I need to count the number of defined periods ( number of months from the dates entered)
Eaxample of Date entries are: 01/03/2017, 02/03/2017,01/04/2017, 02/04/2017.
The code below gives me a count of DefinedPeriodA of 4 when I want it to be 2.
Any help is appreciated.
by DefinedPeriod;if first. DefinedPeriod then DefinedPeriodA= 1;
Assigning a month format doesn't change the stored values of your date variable that is they still remain as date values displaying with your month format. I would suggest to extract month values using month function and the group by month so that you would get your desired result:
/*sample*/
data have;
input defined_period ddmmyy10.;
format defined_period ddmmyy10.;
month=month(defined_period);
datalines;
01/03/2017
02/03/2017
01/04/2017
02/04/2017
;
proc sort data=have;
by month;
run;
data want;
set have;
by month;
if first.month then count=0;
count+1;
if last.month;
run;
Regards,
Naveen Srinivasan
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.