The SAS Output Delivery System and reporting techniques

Difference between columns

Super Contributor
Posts: 648

Difference between columns

id       fico_2014_01	fico_2014_02	fico_2014_03	fico_2014_04	
15013	     668	     668	     668	     670	     

How to find the difference between two months:

 id       fico_2014_01	 fico_2014_02	diff1          fico_2014_03	diff2     fico_2014_04	diff3
15013	     668	     668	  0               668	          0          670	 2

here diff1 is diiference between fico_2014_01	 and fico_2014_02 
     diff2 is diiference between fico_2014_02	 and fico_2014_03  
     diff3 is diiference between fico_2014_03	 and fico_2014_04 

Super User
Super User
Posts: 7,430

Re: Difference between columns

Well, as I always suggest, don't put "data" items in columns headers.  A normalised data strucutre:




Will make your life so much easier to work with the data, and do manipulations.  Then if you need it transposed in the output, transpose it just before the report section.  


Now, you can do this by using arrays, but you need to know how many columns there are (hence why the above strcuture is far more robust and usable):

data want;
  set have;
  array cols{4} fico_2014_01 fico_2014_02...04; /* Note shortened */
  array diffs{3} 8.;
  do i=2 to 4;  /* no comparison on first */

However, again, work with a usable strcuture and your life will be easier.


Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation