BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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?
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
data_null__
Jade | Level 19
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]
SASPhile
Quartz | Level 8
Matrix form of output gives a good idea of the spread of the interval.Thanks a lot.
SASPhile
Quartz | Level 8
if we are to output the number of weeks instead of days?
Peter_C
Rhodochrosite | Level 12
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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1311 views
  • 0 likes
  • 4 in conversation