DATA Step, Macro, Functions and more

Sparsing

Reply
Super Contributor
Posts: 647

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
Super Contributor
Posts: 3,174

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.
Respected Advisor
Posts: 3,777

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: 647

Re: Sparsing

Matrix form of output gives a good idea of the spread of the interval.Thanks a lot.
Super Contributor
Posts: 647

Re: Sparsing

if we are to output the number of weeks instead of days?
Valued Guide
Posts: 2,175

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
Ask a Question
Discussion stats
  • 5 replies
  • 158 views
  • 0 likes
  • 4 in conversation