BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
robertrao
Quartz | Level 8

thats the only way??? i mean creating new variables and using if conditions ?

cant you use any code directly on the DATETIME ?

Thanks

Reeza
Super User

Yes you can. And you seem to know that, so what functions have you tried that didn't work?

This is a place to receive help, not have people do your work for you.

robertrao
Quartz | Level 8

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

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
overmar
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

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)

Peter_C
Rhodochrosite | Level 12

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1024 views
  • 0 likes
  • 6 in conversation