BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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 


1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2003 views
  • 0 likes
  • 2 in conversation