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

dataset:

id    trt start_end

101 TA 2012/02/20

101 TA 2012/03/12

102 TB 2014/03/13

103 TC 2014/03/14

 

Result dataset :

id    sex start_date     end_date

101 M    2012/02/20  2012/03/12

102 F     2014/03/13  2014/03/13

103 M    2014/03/14  2014/03/14

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.  I can't tell from that wether the dates are numeric dates or text for example.

This is just a guess (that they are number) not tested (as no test data in a datastep):

data want (drop=sd);  
  set have (rename=(start_date=sd));
  by id;
  if first.id then start_date=sd;
  if last.id then do;
    end_date=sd;
    output;
  end;
  format start_date end_date yymmdd10.;
run;

Note your results table does not match your test data - no sex, and trt.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.  I can't tell from that wether the dates are numeric dates or text for example.

This is just a guess (that they are number) not tested (as no test data in a datastep):

data want (drop=sd);  
  set have (rename=(start_date=sd));
  by id;
  if first.id then start_date=sd;
  if last.id then do;
    end_date=sd;
    output;
  end;
  format start_date end_date yymmdd10.;
run;

Note your results table does not match your test data - no sex, and trt.

data_null__
Jade | Level 19
data date;
   input id:$3. trt:$2. start_end:yymmdd.;
   format start_end yymmdds10.;
   cards;
101 TA 2012/02/20
101 TA 2012/03/12
102 TB 2014/03/13
103 TC 2014/03/14
;;;;
   run;
proc print;
   run;
proc summary nway;
   class id trt;
   var start_end;
   output out=date2(drop=_:) min=start_date max=end_date;
   run;
proc print;
   run;

Capture.PNG 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 699 views
  • 0 likes
  • 3 in conversation