Hi,
I was learning about different things in Arrays.
I have a couple of questions in the below code:
1)what is the use of vint=.; vext=. for the variables being created;
2)why did we write this
if nmiss(vint, vext)< 2 then output vent_array;
3)what happens if we dont write the above step?????/
Thanks
data vent_array;
format vint vext datetime.;
set have(keep=visit_id mrn1 admission_date discharged
itb1-itb12 ext1-ext12);
by mrn1;
array intubate{12} itb1-itb12;
array extubate{12} ext1-ext12;
do i=1 to 12;
vint=.; vext=.;
if admission_date <= intubate{i} <= discharged then vint=intubate(i);
if admission_date <= extubate{i} <= discharged then vext=extubate(i);
if nmiss(vint, vext)< 2 then output vent_array;
Note: The code is missing at least end; run; at the end.
1) vint=.; vext=.; resets the default value for these variables as missing instead of the value they had on the previous iteration of the do loop.. If the tests that follow are not conclusive, the variables vint or vext will be missing.
2) if nmiss(vint, vext)< 2 The function nmiss returns the number of missing values among its arguments. Here the test condition it will return TRUE if either vint or vext is missing.
3)This datastep creates a new dataset named vent_array that lists the cases where the intb or ext dates are not valid, i.e. they do not occur between the admission and discharge dates.
PG
Thanks PG,
Then I think I messed up with the code...
i was thinking in the below code vent_array dataset contains the cases where itb or extb occurs between admission and discharge dates..(i see that in the dataset there are some observation which have missing either itb or extb.But majority of them have both the values and are with in the range of admission and discharged....please explain
and holding dataset contains the patients whose itb or extb are past the discharged date
data vent_array(keep=visit_id mrn1 admission_date discharged vint vext)
intext.HOLDING(keep= mrn1 vint vext admission_date discharged);
/*purposely removed visit_id from Holding to make it compatible for appending to fresh data eaCH MONTH*/
format vint vext datetime.;
set admitsum_vent(keep=visit_id mrn1 admission_date discharged
itb1-itb12 ext1-ext12);
by mrn1;
array intubate{12} itb1-itb12;
array extubate{12} ext1-ext12;
do i=1 to 12;
vint=.; vext=.;
if datepart(admission_date) <= datepart(intubate{i}) <= datepart(discharged) then vint=intubate{i};
if datepart(admission_date) <= datepart(extubate{i}) <= datepart(discharged) then vext=extubate{i};
if nmiss(vint, vext)< 2 then output vent_array;
if last.mrn1 then do;
do i=1 to 12;
if datepart(intubate{i}) >= datepart(discharged) or datepart(extubate{i}) >= datepart(discharged) then do;
/*guys with int/ext past the discharge date are exported to holding dataset*/
vint=intubate{i};
vext=extubate{i};
output intext.HOLDING;
end;
end;
end;
end;
run;
Why not simply use :
data
vent_array (keep=visit_id mrn1 admission_date discharged vint vext)
intext.HOLDING (keep= mrn1 admission_date discharged vint vext);
format vint vext datetime.;
set admitsum_vent;
array intubate{12} itb1-itb12;
array extubate{12} ext1-ext12;
do i=1 to 12;
vint=intubate{i};
vext=extubate{i};
if admission_date <= vint <= discharged and
admission_date <= vext <= discharged then output vent_array;
if vint > discharged or vext > discharged then output intext.HOLDING;
end;
run;
PG
HI,
thanks for your help. The last. Concept is necessary because there are repeats for the mrn1 and it is only for the record encounter we want to check if the patient intubate or extubate is greater than discharge date because by doing that we will know that the patient is not yet discharged completely and we want to hold that records for future analysis agagain
thanks
This then?
data
vent_array (keep = visit_id mrn1 admission_date discharged vint vext)
intext.HOLDING (keep = mrn1 admission_date discharged vint vext);
format vint vext datetime.;
set admitsum_vent; by mrn1;
array intubate{12} itb1-itb12;
array extubate{12} ext1-ext12;
do i = 1 to 12;
vint=intubate{i};
vext=extubate{i};
if (admission_date <= vint <= discharged) and
(admission_date <= vext <= discharged) then output vent_array;
if last.mrn1 and (vint > discharged or vext > discharged) then output intext.HOLDING;
end;
run;
Hi,
I am stuck in this logic.Could someone help me figure this out?
As PG explained
if nmiss(vint, vext)< 2 then output vent_array;means
if either of them is missing then output to vent_array
But in my case I am getting observations in the vent_array where both of them are non missing as well as either missing
How am I able get to this results...
i wanted those observations which satify those conditions to be in that vent_array
But that highlighted statement usage should not give what I wanted .....But to my surprise
Thanks
I am confused. Your first restatement of the meaning is wrong, but the second is right.
Perhaps the issue you are seeing is because of the loop over 12 elements of the array?
Because of that you will see values of <visit_id mrn1 admission_date discharged> in VENT_ARRAY when ANY of the 12 pairs have one or zero missing values. The only source records that will not send any records to VENT_ARRAY will be those where ALL of the 24 original variables are missing. Adding the index variable I to the keep list for VENT_ARRAY should help you see this.
Cleaarly I see that after I used the code.
the vent_array dataset has observations for which there is non missing vint and vext as well
like shown and also either of them missing
vint vext
value value
missing value
value missing
And these are all within the admissin discharge date ranges...
EVEN THE ONES WITH :
missing value
THE VALUE IS WITHIN THE DATE RANGE
So How can I get to kNOW THE OBSERVATIONS WHOSE VINT AND VEXT ARE NOT WITHIN THE VALID RANGE OF INTUBATE AND EXTUBATES SEPERATELY????????/
aLSO WHEN WE SAID
IF nmiss(vint, vext)< 2 then output vent_array;
WHY IS IT STILL OUTPUTTING OBSERVATIONS WHERE BOTH VALUES ARE NON-MISSING
LIKE
VALUE VALUE AS SHOWN ABOVE
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.
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.