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

Hello


I have a list of hospital where chart number is the patient identifier and account number is the unique identifier for the visit.  I would like to create a data set of just the first visit for the chart number and the last visit for the chart number.

data have;

input @1  chartno $6.
         @7  acctno  $3.
         @10 admdate yymmdd8.
         @18 sepdate yymmdd8.
        @26 postal $6.
   ;

format admdate yymmdd10. sepdate yymmdd10.;

cards;
1111110012012032920120331N0H2C1
2222220022012050120120515L4M6X6
3333330032012060120120607L4N4A8
1111110042012040220120410N4L1H4
4444440052012060320120615N4L1S7
5555550062012053120120603L0L2K0
2222220072012070120120713L4M6X6
2222220082012072020120725L9Y2M7
4444440092012081320120817N4L1S7
3333330102012061520120621L4N4A8
1111110112012110120121130N4L1H4
run;

For the above for chartno 111111 I want the data set to only include the March 31, 2012 visit and the November 30, 2012 visit.  Any assistance greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

First/Last processing should work for this.

data want;

set have;

by chartno;

if first.chartno or last.chartno;

run;

View solution in original post

4 REPLIES 4
Reeza
Super User

First/Last processing should work for this.

data want;

set have;

by chartno;

if first.chartno or last.chartno;

run;

cu8sfan
Calcite | Level 5

Not sure if I'm missing the problem here. Sort by chartno and date, set with by statement and use first. and last. variables:

proc sort data = have;

   by chartno

      admdate

      ;

run;

data FirstAndLast;

   set have;

   by chartno

      admdate

      ;

   if    first.chartno

      or last.chartno

      ;

run;

ballardw
Super User

Or

Proc sql;

     create table want as

     select chartno, min( admdate) as FirstVisit format=yymmdd10., max(admdate) as LastVisit format=yymmdd10.

     from have

     group by chartno;

quit;

shellp55
Quartz | Level 8

Thank you so much for all the really great answers.  I chose Reeza's only because simple is best!  I knew when I posted it the answer would be simple but I could not get the correct syntax. Thanks again.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1868 views
  • 0 likes
  • 4 in conversation