data R11time;
set R11a;
cnot_hour= put(not_hour,z2.);
cnot_min= put(not_min,z2.);
not_tim= cat(cnot_hour,cnot_min);
where (not_hour >=1 and not_hour <=24);
where (not_min >=0 and not_min <=60);
nottime=input(not_tim,hhmmss4.);
format nottime time5.;
drop cnot_hour cnot_min not_tim;
carr_hour= put(arr_hour,z2.);
carr_min= put(arr_min,z2.);
arr_tim= cat(carr_hour,carr_min);
where (arr_hour >=1 and arr_hour <=24);
where (arr_min >=0 and arr_min <=60);
arrtime=input(arr_tim,hhmmss4.);
format arrtime time5.;
drop carr_hour carr_min arr_tim;
chosp_hr= put(hosp_hr,z2.);
chosp_mn= put(hosp_mn,z2.);
hosp_tim= cat(chosp_hr,chosp_mn);
where (hosp_hr >=1 and hosp_hr <=24);
where (hosp_mn >=0 and hosp_mn <=60);
hosptime=input(hosp_tim,hhmmss4.);
format hosptime time5.;
drop chosp_hr chosp_mn hosp_tim;
tan = (nottime - actime)/60;
tasa = (arrtime - actime)/60;
taha = (hosptime - actime)/60;
tnsa = (arrtime - nottime)/60;
tnha = (hosptime - nottime)/60;
tsaha = (hosptime - arrtime)/60;
run;
Wow!
Thanks for your quick response.
It worked.
I had tried writing all the WHERE's in one line but I was using an OR ..and it makes sense, OR will not pick all the columns.
And I noticed that after using 'and' more than once, the color changes from blue to the variable color. I guess that doen not matter.
A proc univariate showed that the ranges are within the expected values.
Thank you so much.
Only one where condition in a data step will be effective, namely the last one. Combine all your where conditions into one with and.
Wow!
Thanks for your quick response.
It worked.
I had tried writing all the WHERE's in one line but I was using an OR ..and it makes sense, OR will not pick all the columns.
And I noticed that after using 'and' more than once, the color changes from blue to the variable color. I guess that doen not matter.
A proc univariate showed that the ranges are within the expected values.
Thank you so much.
There are a few basic concepts about a WHERE statement that you need to know.
First, when you use multiple WHERE statements, each one replaces the ones before. So the last WHERE statement is the only one that has any impact.
Second, WHERE screens out the entire observation from all processing. So if HOSP_MIN = 80, that observation is excluded from all the calculations, including the calculations for NOTTIME and ARRTIME. Is that your intention?
It is conceivable that IF THEN statements would be more suitable. For example you now have:
hosp_tim= cat(chosp_hr,chosp_mn);
where (hosp_hr >=1 and hosp_hr <=24);
where (hosp_mn >=0 and hosp_mn <=60);
hosptime=input(hosp_tim,hhmmss4.);
It might be that you would prefer to use:
if (hosp_hr >=1 and hosp_hr <=24)
and (hosp_mn >=0 and hosp_mn <=60)
then do;
hosp_tim= cat(chosp_hr,chosp_mn);
hosptime=input(hosp_tim,hhmmss4.);
end;
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.