I have two variables like shown below and I want times in a particular month for example MARCH
an ID should have IN_TIME in MAy or June whereas the OUT_TIME in JUNE exclusively
is the following code a right approach
HAVE:
ID IN_TIME OUT_TIME
001 April May
001 June July
001 march march
001 march july
001 march june
001 may may
001 may june
001 june june
data may_in (keep=ID IN_TIME ) june_in(keep=ID IN_TIME) jun_out(keep=ID OUT_TIME);
set have;
if May1<=IN_TIME<=May31 then output may_in;
if June1<=IN_TIME<=June30 then output june_in;
if June1<=OUT__TIME<=June30 then output june_out;
run;
I will rename IN_tiME and OUT_TIME in all the 3 datasets to a common name and append them so that I have all of them in a single variable
Thanks
You have the general idea. If your date variables (IN_TIME and OUT_TIME) are SAS date variables, then you could modify it as follows. Also, you can use the RENAME= option to rename the variables on the fly.
data may_in (drop=OUT_TIME rename=(IN_TIME=TIMEVAR))
jun_in (drop=OUT_TIME rename=(IN_TIME=TIMEVAR))
jun_out (drop=IN_TIME rename=(OUT_TIME=TIMEVAR));
set have;
if month (IN_TIME) = 5 then output may_in;
if month (IN_TIME) = 6 then output jun_in;
if month (OUT_TIME)=6 then output jun_out;
run;
Is there a way i can create a flag variable for may_in jun_in datasets as flag="IN"
and flag='OUT" for jun_out dataset in the same step???
Thanks
Hi robertrao,
You can flag it. .
If month(in_time)=5 then do;
Flag='IN';
Output May_in;
End;
If month(in_time)=6 then do;
Flag='IN';
Output Jun_in;
End;
If month(out_time)=6 then do;
Flag='OUT';
Output Jun_out;
End;
YOu can use these three conditions.. I hope it works for you..
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.