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

Hello ,

I am trying to create a new variable for days between just the first visit and the second visit in each year. Also I am trying to create another variable for number of visit for each year. Could you please help me for this issue because I am struggling. Here is a sample of the dataset. Thank you for your time and your help in advance.

 

 

 

 

data Member_Data_Sample;
input VISIT_DATE :date9. MEMBER_ID $ VISIT_YEAR VISIT_STATUS;
format  VISIT_DATE :date9.;
datalines;
06NOV2013 AA10450Z 2013 0 
05JUN2014 AA10450Z 2014 1 
26JUN2014 AA10450Z 2014 1 
21AUG2014 AA10450Z 2014 1 
18SEP2014 AA10450Z 2014 1 
03DEC2014 AA10450Z 2014 1 
11MAR2015 AA10450Z 2015 1 
15APR2015 AA10450Z 2015 1 
07OCT2015 AA10450Z 2015 1 
13OCT2015 AA10450Z 2015 1 
26OCT2015 AA10450Z 2015 1 
09NOV2015 AA10450Z 2015 1 
07DEC2015 AA10450Z 2015 1 
21DEC2015 AA10450Z 2015 1 
19APR2017 AA10450Z 2017 1 
10SEP2018 AA10450Z 2018 0 
15APR2019 AA10450Z 2019 1 
;
run;

data Member_Data_Sample;
input VISIT_DATE :date9. MEMBER_ID $ VISIT_YEAR VISIT_STATUS;
format VISIT_DATE :date9.;
datalines;
06NOV2013 AA10450Z 2013 0
05JUN2014 AA10450Z 2014 1
26JUN2014 AA10450Z 2014 1
21AUG2014 AA10450Z 2014 1
18SEP2014 AA10450Z 2014 1
03DEC2014 AA10450Z 2014 1
11MAR2015 AA10450Z 2015 1
15APR2015 AA10450Z 2015 1
07OCT2015 AA10450Z 2015 1
13OCT2015 AA10450Z 2015 1
26OCT2015 AA10450Z 2015 1
09NOV2015 AA10450Z 2015 1
07DEC2015 AA10450Z 2015 1
21DEC2015 AA10450Z 2015 1
19APR2017 AA10450Z 2017 1
10SEP2018 AA10450Z 2018 0
15APR2019 AA10450Z 2019 1
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set member_data_sample;
    by member_id visit_year;
    delta_days=visit_date-lag(visit_date);
    if first.visit_year then do;
        delta_days=.;
        counter=0;
    end;
    counter+1;
run;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
data want;
    set member_data_sample;
    by member_id visit_year;
    delta_days=visit_date-lag(visit_date);
    if first.visit_year then do;
        delta_days=.;
        counter=0;
    end;
    counter+1;
run;
--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 331 views
  • 0 likes
  • 2 in conversation