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
Well, as I always suggest, don't put "data" items in columns headers. A normalised data strucutre:
ID YEAR MONTH VALUE
...
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 */ diff{i-1}=cols{i}-cols{i-1}; end; run;
However, again, work with a usable strcuture and your life will be easier.
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.