In the same dataset I am trying to acheive two things;
1)to extract the last item in the UNITS array
2)to do the difference between time pairs(Datetime 16. format) and sum them up..
I am not getting the days right....Days are shown as 10008.3465 etc etc Could you help me correct it
data admit2;
set vnt_admit;
array units unext10-unext1;
array itb int:;
array ext ext:;
do over units;
if not missing (units) then do;
new=units;LEAVE;
end;
END;
do i=1 to dim(itb);
if 2=N(int(i),ext(i)) then duration=sum(duration,ext(i)-int(i));
days=duration/86400;
end;
run;
EVEN I DO IT AS SEPERATE DATASETS I DONT GET IT .......
Thanks
Once you define this array:
array itb int:;
You have to refer to the array as ITB. You can't refer to the array as INT. INT(i) is applying the INTEGER function to i, not referring to the array at all.
So anywhere you have int(i), replace it with itb(i).
Good luck.
Once you define this array:
array itb int:;
You have to refer to the array as ITB. You can't refer to the array as INT. INT(i) is applying the INTEGER function to i, not referring to the array at all.
So anywhere you have int(i), replace it with itb(i).
Good luck.
Great Thanks....
Hi ,
Is there anyway i can do the same operation using a single do loop in the below code????
1)to extract the last item in the UNITS array
2)to do the difference between time pairs(Datetime 16. format) and sum them up..
data admit2;
set vnt_admit;
array units unext10-unext1;
array itb int:;
array ext ext:;
do over units;
if not missing(units) then do;
new=units;LEAVE;
end;
END;
do i=1 to dim(itb);
if 2=N(itb(i),ext(i)) then duration=sum(duration,ext(i)-itb(i));
end;
days=duration/86400;
run;
Possibly, but it would only make the program more complex and difficult to follow. Is there some reason you need to do this? If so, a related question would be whether you know how many INT and EXT values you have.
Hi,
I was thinking of different ways since i am very naive to using arrays
secondly, yes in this case i know the value for INT AND EXT its 10 .
but all 10 need not necessarily have values upto 10......some might have values only for 4 pairs and the rest pairs are blank
Some might have values all the way thru 10
Thanks
OK, having 10 elements in each array simplifies things. You could try:
do i=1 to 10;
if missing(new) then new=units{i};
if 2=N(itb{i}, ext{i}) then duration = sum(duration, ext{i} - itb{i});
end;
I think you have mistaken
if missing(new) then new=units{i};
FOR
if not missing(units) then new=units{i}; because we need the non missing value
Also, even if we do this below
if not missing(units) then new=units{i}; we are not still making sure that it is grabbing the last non missing!!! we want the last non missing
Thanks
No, the logic is just the way I intended it.
The program keeps placing the units{i} elements into NEW. Once NEW has a value, the remaiing units{i} values can be ignored.
i think i dint get it still...Could you please explain
How can we use the variable NEW before we even created it???
and which step in the code makes sure that it picks the last non missing value from the array UNITS??
Thanks
Q1. The DATA step operates in two phases. First, it examines your statements, checks syntax, and sets up storage space for all your variables. This is generally called the compilation phase of the data step. Once all this set-up work is done, NEW exists. Only then does the DATA step enter the second phase and actually execute your statements. If this is something you want to study up on, you can probably find two related papers (paraphrasing the titles here): The SAS Supervisor (Don Henderson), and How MERGE Really Works (Robert Virgile).
Q2. The list of variables in the UNITS array is UNEXT10-UNEXT1. So the first time through the DO loop, when i=1, UNEXT10 gets copied to NEW. At this point, NEW may be populated or it may be missing ... it depends on what was in UNEXT10. The second through the DO loop, when i=2, the loop examines whether NEW is missing or not. If it's missing, UNEXT9 gets copied into NEW. So once NEW has a value, any remaining elements within the UNITS array will not get placed into NEW.
Thanks for the detailed explanation.
Reading very closely, i think i=2 in the below menioned quote...Am i correct???
"The second through the DO loop, when i=1, the loop examines whether NEW is missing or not."
2)And after all the modifications doesnt the final code look like this???
data admit2;
set vnt_admit;
array units unext10-unext1;
array itb int:;
array ext ext:;
do i=1 to 10;
if missing(new) then new=units{i};
if 2=N(itb{i}, ext{i}) then duration = sum(duration, ext{i} - itb{i});
end;
days=duration/86400;
run;
Thanks
Correct on all counts. I fixed i=1, making it i=2 for anybody else reading it.
Thanks once again for your time.
This is a very nice place to learn and share the subject
In the below can i use any name for the variable being created?????
if 2=N(itb{i}, ext{i}) then duration = sum(duration, ext{i} - itb{i});
Example:
if 2=N(itb{i}, ext{i}) then Time = sum(duration, ext{i} - itb{i});
Can anyone explain the logic??
Thanks
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.