BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cactooos
Obsidian | Level 7

Hi,

I would like to calculate difference between START - END for each name.

Assuming: table is already sorted by name date,

START is always first,

has to be at least one START per name but always there is a sequence START END START..

 

Table have like this:

DATA HAVE;
LENGTH name $10. var1 $5.;
 INPUT name $ date :date9. var1 $;
 format date date9. ;
 DATALINES;
aaa 10JUN2020 START
aaa 15JUN2020 END
bbb 10JUL2020 START
bbb 20JUL2020 END
bbb 25JUL2020 START
bbb 01SEP2020 END
ccc 20JUN2020 START
ddd 15JUL2020 START
ddd 30JUL2020 END
ddd 02SEP2020 START
;
RUN;

want like this:

cactooos_0-1610380614425.png

I know how to do it within the group but got lost with START END piece

 

Huge thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

data want;
    set have;

    ldate=lag(date);
    if var1="START" then dif=0;
    else dif=intck('day', ldate, date);
run;

 Edit : removed useless by name statement.

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

data want;
    set have;

    ldate=lag(date);
    if var1="START" then dif=0;
    else dif=intck('day', ldate, date);
run;

 Edit : removed useless by name statement.

cactooos
Obsidian | Level 7
Works perfectly, thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 650 views
  • 0 likes
  • 2 in conversation