Hi,
I have variables like shown in the dataset
IN and OUT are datetimes
condition:
if the month&year is from OCT2013 to DEC 2013 and
if OUT is missing but has a datetime under the IN variable or VICE VERSA I want to export those records to a seperate dataset
ID IN OUT
101 . 03OCT2013:03:42
102 07OCT2013:18:58 .
Thanks
m1=month(datepart(in));
m2=month(datepart(out));
y1=year(datepart(in));
y2=year(datepart(out);
if (m1>=10 and m1<=12 and y1=2013) or (m2>=10 and m2<=12 and y2=2013) then do;
...
end;
m1=month(datepart(in));
m2=month(datepart(out));
y1=year(datepart(in));
y2=year(datepart(out);
if (m1>=10 and m1<=12 and y1=2013) or (m2>=10 and m2<=12 and y2=2013) then do;
...
end;
thats the only way??? i mean creating new variables and using if conditions ?
cant you use any code directly on the DATETIME ?
Thanks
Honestly, I dont know if I can use any direct way.
May be the way i asked the question was not proper and gave the impression that I knew it..
Sorry about that
Thanks
robertrao wrote:
thats the only way??? i mean creating new variables and using if conditions ?
cant you use any code directly on the DATETIME ?
Thanks
No one ever said or implied that this is the only way to do something. It's an example, one way to do it, you could easily combine what I did into one statement and not create additional variables (although I fail to see a problem with creating temporary variables, you don't have to save the additional variables). What exactly is the problem with doing it with additional variables?
You could also do:
For the time constraint:
if ('01oct2013'd<=datepart(in) <='31dec2013'd) or ('01oct2013'd<=datepart(out) <='31dec2013'd) then do;
This way you don't have to create new variables, which it seemed that you were disinclined to do.
For the second part you could do the code below.
For the missing constraint:
if (in = . and out ~=.) or (in~=. and out=.) then do;
output;
end;
Hope this is more what you were looking for.
What did you try? Did it give you error messages? Or did it give you wrong the results?
You seem to have three conditions in your selection criteria.
1) IN = .
2) OUT = .
The third part is a little vague.
One way to interpret it is that the interval IN-OUT completely covers oct/nov/dec of 2013.
(in <= '01OCT2013:00:00'dt and '01DEC2013:00:00'dt <= out)
condition:
if the month&year is from OCT2013 to DEC 2013 and
if OUT is missing but has a datetime under the IN variable or VICE VERSA I want to export those records to a seperate dataset
ID IN OUT
101 . 03OCT2013:03:42
102 07OCT2013:18:58
If n( in, out)=1 & "1oct2013:0:0:0"dt <= max( in, out ) <= "31Dec2013:23:59:59.999"dt then output separate_data
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.