## Sparsing

Super Contributor
Posts: 713

# Sparsing

Code Date
A1 4/30/2010
B1 5/16/2010
C1 5/30/2010
D1 6/16/2010
E1 4/30/2010

How to display only those codes that are 4 weeks apart from each other?
Super Contributor
Posts: 3,176

## Re: Sparsing

Use a DATA step to read-up the data, then use the LAG function and also use INTCK to compute delta/difference between consecutive observations.

Scott Barry
SBBWorks, Inc.
Posts: 3,852

## Re: Sparsing

This might get you started.

[pre]
data test;
input Code:\$2. Date:mmddyy.;
format date mmddyy10.;
cards;
A1 4/30/2010
B1 5/16/2010
C1 5/30/2010
D1 6/16/2010
E1 4/30/2010
;;;;
run;
proc distance method=EUCLID out=dist shape=square;
id code;
var interval(date);
run;
proc print;
run;
[/pre]

It produces this output.

[pre]
Obs Code A1 B1 C1 D1 E1

1 A1 0 16 30 47 0
2 B1 16 0 14 31 16
3 C1 30 14 0 17 30
4 D1 47 31 17 0 47
5 E1 0 16 30 47 0
[/pre]
Super Contributor
Posts: 713

## Re: Sparsing

Posted in reply to data_null__
Matrix form of output gives a good idea of the spread of the interval.Thanks a lot.
Super Contributor
Posts: 713

## Re: Sparsing

Posted in reply to data_null__
if we are to output the number of weeks instead of days?
Valued Guide
Posts: 2,191

## Re: Sparsing

cartesian join or reflex join are terms to describe "every-way" join
why not do all the work your self with an sql step
, like (to create the list of code pairs that are 4 weeks apart)
/* interval between dates measured in weeks*/[pre]
select a.code as code_a
, b.code as code_b
, a.date as date_a
, b.date as date_b
, from data a, data b
where range( a.date, b.date)/7 =between 3.5 and 4.49 [/pre]
or something like that (depending on the "precision" of 4 weeks)

if you just want counts of the code_a, code_b pairs then
use count(*) instead of a.date, b.date in the "select columns list" and group by
code_a, code_b
Discussion stats
• 5 replies
• 214 views
• 0 likes
• 4 in conversation