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

Happy Monday All! 

 

So here is my questions that I hope can be solved with relative ease- 

I have an array that works in that  it calculates if notetime{i} is between the Unit_startTime_Day & Unit_EndTime_Day, tallies the sum of the entries that match and then keeps the notetimes that match the condition 

 

But here is what I am trying to do- 

In line2, I am trying to make it so that notetime4 becomes notetime1, notetime5 becomes notetime2, etc etc as there can be up to x number of notes but it becomes difficult for users to scroll through when its note22-note1000

 

code below table-  I apologize in advance that there is no input table  but hopefully someone can point me to the way... 

Thanks in advance for your help.

 

LB 

 


data all_notes;
retain date time_days pt_hours total_notes;
merge unit_time note_times;
by PAT_ENC_CSN_ID;

array notes (*) note:;
array notep {&notect};
array notetime {&notect};
do i=1 to dim(notes);
if start2<=notes(i)<=end_t then notep(i)=1; else notep(i)=0;


if notep(i)=1 then notetime(i)=notes(i);else notetime(i)=.;
end;

 

total_notes=sum(of notep1-notep&notect);
format notetime1-notetime&notect datetime19.;
drop _name_ _label_ note1-note&notect /*notep1-notep&notect* i*/ department_id DEPARTMENT_NAME tot_hrs;
rename start2=Unit_StartTime_Day END_T=Unit_EndTime_Day time_days=pt_days;
if department_id=. then delete;

run;

 

 

 

pat_enc_csn_id Unit_StartTime_Day Unit_EndTime_Day notetime1 notetime2 notetime3 notetime4 notetime5 notetime6 notetime7
1234 24Jul18:04:19:00 24Jul18:23:59:59 24Jul18:02:35:00 24Jul18:08:42:00 24Jul18:22:58:00 . . . .
1234 25Jul18:00:00:00 25Jul18:23:59:59 . . . 25Jul18:03:25:00 25Jul18:08:18:00 . .
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Not too sure I understand but this might to do what you want:

data HAVE;
 infile cards dlm='09'x dsd;
 input PAT_ENC_CSN_ID	(UNIT_STARTTIME_DAY	UNIT_ENDTIME_DAY	NOTETIME1	NOTETIME2	NOTETIME3	NOTETIME4	NOTETIME5	NOTETIME6	NOTETIME7) (: datetime16.);
 format                UNIT_STARTTIME_DAY	UNIT_ENDTIME_DAY	NOTETIME1	NOTETIME2	NOTETIME3	NOTETIME4	NOTETIME5	NOTETIME6	NOTETIME7 datetime.;
 cards;
1234	24Jul18:04:19:00	24Jul18:23:59:59	24Jul18:02:35:00	24Jul18:08:42:00	24Jul18:22:58:00	.	.	.	.
1234	25Jul18:00:00:00	25Jul18:23:59:59	.	.	.	25Jul18:03:25:00	25Jul18:08:18:00	.	.
run;
data WANT; 
set HAVE;
  array NOTES    [*] NOTETIME: ;
  array NOTEP    [7] ;
  array NOTETIME [7] NEW1-NEW7;
  format NEW: datetime.;
  POS=1;
  do I=1 to 7;
    if UNIT_STARTTIME_DAY <= NOTES[I] <= UNIT_ENDTIME_DAY then do;
      NOTEP[I]=1;
      NOTETIME[POS]=NOTES[I];
      POS+1; 
    end;
  end;
  TOTAL_NOTES=sum(of NOTEP1-NOTEP7);
run;
proc print noobs; 
  var PAT_ENC_CSN_ID NEW:; 
run;

 

PAT_ENC_CSN_ID NEW1 NEW2 NEW3 NEW4 NEW5 NEW6 NEW7
1234 24JUL18:08:42:00 24JUL18:22:58:00 . . . . .
1234 25JUL18:03:25:00 25JUL18:08:18:00 . . . . .

 

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Not too sure I understand but this might to do what you want:

data HAVE;
 infile cards dlm='09'x dsd;
 input PAT_ENC_CSN_ID	(UNIT_STARTTIME_DAY	UNIT_ENDTIME_DAY	NOTETIME1	NOTETIME2	NOTETIME3	NOTETIME4	NOTETIME5	NOTETIME6	NOTETIME7) (: datetime16.);
 format                UNIT_STARTTIME_DAY	UNIT_ENDTIME_DAY	NOTETIME1	NOTETIME2	NOTETIME3	NOTETIME4	NOTETIME5	NOTETIME6	NOTETIME7 datetime.;
 cards;
1234	24Jul18:04:19:00	24Jul18:23:59:59	24Jul18:02:35:00	24Jul18:08:42:00	24Jul18:22:58:00	.	.	.	.
1234	25Jul18:00:00:00	25Jul18:23:59:59	.	.	.	25Jul18:03:25:00	25Jul18:08:18:00	.	.
run;
data WANT; 
set HAVE;
  array NOTES    [*] NOTETIME: ;
  array NOTEP    [7] ;
  array NOTETIME [7] NEW1-NEW7;
  format NEW: datetime.;
  POS=1;
  do I=1 to 7;
    if UNIT_STARTTIME_DAY <= NOTES[I] <= UNIT_ENDTIME_DAY then do;
      NOTEP[I]=1;
      NOTETIME[POS]=NOTES[I];
      POS+1; 
    end;
  end;
  TOTAL_NOTES=sum(of NOTEP1-NOTEP7);
run;
proc print noobs; 
  var PAT_ENC_CSN_ID NEW:; 
run;

 

PAT_ENC_CSN_ID NEW1 NEW2 NEW3 NEW4 NEW5 NEW6 NEW7
1234 24JUL18:08:42:00 24JUL18:22:58:00 . . . . .
1234 25JUL18:03:25:00 25JUL18:08:18:00 . . . . .

 

 

LB
Quartz | Level 8 LB
Quartz | Level 8

perfect! Thanks! 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 666 views
  • 0 likes
  • 2 in conversation