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

Hi

I am using Base SAS 9.3.  I have a patient file where one visit is one line of data.  With the way procedural data is saved, if there are many procedures in one episode then the surgeon only shows up on the entry for the episode.  I would like it to show up on all applicable records.  A change in episode is indicated by a change in procedure date.  OR you could have two different doctors in one episode but then a new one would be present (as in reg 001 below). 

data test_grp ;

infile datalines truncover;

input @1 regno $3.

      @4 PxStDate1 yymmdd8.

      @12 PxDoc1 $5.

      @17 Px1 $7.

      @24 PxStDate2 yymmdd8.

      @32 PxDoc2 $5.

      @37 Px2 $7.

      @44 PxStDate3 yymmdd8.

      @52 PxDoc3 $5.

      @57 Px3 $7.

      @64 PxStDate4 yymmdd8.

      @72 PxDoc4 $5.

      @77 Px4 $7.;

format PxStDate1-PxStDate4 yymmdd10.;

cards;

00120120329Smith1RB89LA        Jones1RB87LA             2OT71LA

00220120417Jones1RM89LA             1RD89LA20120420Green3OT20WE

00320120420Brown1VA53LA20120425Jones1VC55LA20120430Green3OT20WE

00420120513Green1RM89LA             1RD89LA             2OT71LA20120525Jones3OT20WE

00520120602Smith1VA53LA             1VC55LA             2OT20WE20120623Jones3OT20WE

00620120329Brown1RB89LA             1RB87LA             2OT71LA

007

run;

So for reg 001, Jones should also show up for doc3 because that is blank and there is a procedure.  It's not Smith because there was an entry in doc2 for Jones.  For reg 002, Jones should also be doc2 (same episode because no new date).  For reg 004, Green should be doc2 and doc3.  And so on.

Also, can the method anyone suggests also be used for dates?  Because the same scenario applies for the dates in that they only show up once and I would like them to show up for each procedure within an episode.

Thanks for any and all assistance!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use arrays, this way :

data want;
set test_grp;
array PxDoc{*} PxDoc1-PxDoc4;
array PxStDate{*} PxStDate1-PxStDate4;
array Px{*} Px1-Px4;
do i = 2 to 4;
     if not missing(Px{i}) then do;
          PxDoc{i} = coalescec(PxDoc{i},PxDoc{i-1});
          PxStDate{i} = coalesce(PxStDate{i},PxStDate{i-1});
          end;
     end;
drop i;
run;

proc print noobs; run;

PG

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Use arrays, this way :

data want;
set test_grp;
array PxDoc{*} PxDoc1-PxDoc4;
array PxStDate{*} PxStDate1-PxStDate4;
array Px{*} Px1-Px4;
do i = 2 to 4;
     if not missing(Px{i}) then do;
          PxDoc{i} = coalescec(PxDoc{i},PxDoc{i-1});
          PxStDate{i} = coalesce(PxStDate{i},PxStDate{i-1});
          end;
     end;
drop i;
run;

proc print noobs; run;

PG

PG
shellp55
Quartz | Level 8

Hi PG

This is amazing!  Thank you so much. I'll apply to my real data and hope for the same success.

Thanks again.

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