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

Hello all.

I would like to complete the table on the left side with a variable time span based on the years.

I hope that you can help me.

 

SAS.png

1 ACCEPTED SOLUTION

Accepted Solutions
AhmedAl_Attar
Rhodochrosite | Level 12
To get the time_span numbers listed in the "Aim:", I think the query should be
proc sql;
create table want as
select id,year,(range(year)+1) as time_span
from have
group by id ;
quit;

View solution in original post

4 REPLIES 4
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @cnn96 

I think this will do it.

First use a select to calculate the time_span for each PatientID then add the calculated value with a join. 

Note: Untested, because you didn't provide a data step to generate test data. 

 

proc sql;
  create table b as
    select distinct PatientID, count(*) as time_span
    from mylib.mytable
    group by PatientID;
quit;

proc sql;
  create table table_timespan as
    select a.*, b.time_span
    from mylib.mytable as a, b
    on a.PatientID = b.PatientID;
quit;
Ksharp
Super User
proc sql;
create table want as
select id,year,range(year) as time_span
from have
group by id ;
quit;
AhmedAl_Attar
Rhodochrosite | Level 12
To get the time_span numbers listed in the "Aim:", I think the query should be
proc sql;
create table want as
select id,year,(range(year)+1) as time_span
from have
group by id ;
quit;
cnn96
Fluorite | Level 6

Thank you very much. This way it worked the way i wanted it to.😊

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 4 replies
  • 544 views
  • 3 likes
  • 4 in conversation