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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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