Hi Paige, thanks a lot for your feedback and valuable comments!
The reasons I said my logic is easier to understand is as follows: 1) @Tom use one single statement to calculate the days for each month, like this:
days=min(date2, intnx('month',month,0,'e') )-max(month,date1)+1;
I use two data steps (one for months and the other one for days, in my last thread) with many more statements to calculate the days for each month, like this:
/*determine start and end day of the 1st month*/ if i=0 then do; startday=date1; endday=intnx('month',date1,0,'end'); end; /*determine start and end day of the last month*/ else if i=intck('month',date1,date2) then do; startday=intnx('month',date2,0); endday=date2; end; /*determine start and end day of other months*/ else do; startday=mdy(month(month),01,year(month)); endday=intnx('month',startday,0,'end'); end; /*calcualte days of each month*/ days=endday-startday+1;
The logic of my version is: explicitly show every single step of thinking with one SAS statement or step. And my steps of thinking are shown in the notes in the code above. 2) For me, who is not good at math, writing code this way saves a lot of more complex thinking (and therefore consumes more coding steps), i.e., when you think a basic and single step you explicitly write it out. @Tom combined several thinking steps using one statement which integrates and presents different calculations for the days of the 1st month, the last month, and other months. Maybe what @Tom did is the common way of thinking and common practice for people who have science and math background, but for people who is not that good at math, perhaps my steps is easier to understand and follow. Also, if this code needs to be developed to macros, I think my steps is necessary. Nevertheless, I will learn to combine detailed and basic steps and statements using more advanced and comprehensive thinking and coding techniques later on.
I agree with you that @Tom created a tall dataset at first, and then base on which calculated the days, i.e., creating a tall dataset makes things easier, comparing to @quickbluefish 's solution which at first uses an array and then a loop with advanced functions. So I followed @Tom 's steps to write my version. I have just started to learn array and nested loops and advanced functions and did not follow @quickbluefish 's solution. I will learn those techniques later on. The other reason I followed @Tom 's solution is that the proc sort and proc report steps help me review what I learnt, it is a good example and good practice for me.
By talking about array and (nested) loops I was indeed refer to @quickbluefish 's solution. You are right about this. Thanks again @PaigeMiller for your valuable comments, which offers me ideas on what aspects I need to improve and need to think differently.
... View more