Output when more then one Conditions fulfilled

Reply
N/A
Posts: 0

Output when more then one Conditions fulfilled

Hi all,

I have some animal. It was registrated when they are at one special place on the field (water food toys). Now I'm interested which time they need to visited all places.
I could create a lot of datasets which where option like:
data test1a;
set test;
where animal=1 place='a';
run;

And the some for the other places and after that for the other animal and places.
Then I look to the minimum of the Time. after then I merge the place from a animal to one dataset. and look to the maximum time and I have the Time which need one animal the same I repeat for the other.
But I think SAS could it better and faster.
How can I realize this in SAS smarter?

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Output when more then one Conditions fulfilled

Suggest you reply to your post with a small sample data set, demonstrating the input and also what you want to see as the outcome from SAS. It is quite possible that one or more PROC MEANS/SUMMARY and some DATA step MERGE executions could get you the combination of info desired. Also you may want to explore PROC SQL and JOIN with your data, as well.

I believe that once you reveal some input/output data information then you might even see the possiblities using SAS DATA step and various PROC executions to get your results.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Example

The Starttime ist 12:00
Place Animal Time
a 2 12:23:12
a 2 12:23:56
b 1 13:16:34
c 2 13:18:32
c 2 13:19:37
c 1 13:23:12
c 2 13:30:51
a 1 13:31:50
a 2 13:33:00
a 2 13:33:13
b 1 13:36:34
b 2 13:42:39
b 1 13:45:29


This provisional result:

Place Animal Time
a 1 13:31:50
b 1 13:16:34
c 1 13:23:12
a 2 12:23:12
b 2 13:42:39
c 2 13:18:32

The final result should be
Animal Time diff
1 13:31:50 1:31:50
2 13:42:39 1:42:39

diff=time-12:00

animal 1 need 1 hour 31 minutes and 50 seconds
animal 2 need 1 hour 42 minutes and 39 seconds


Lex Message was edited by: Lex
Super Contributor
Super Contributor
Posts: 3,174

Re: Example

As suggested, you will want to explore using the DATA step to read up your data, followed by PROC MEANS/SUMMARY, then a DATA step MERGE to re-introduce your MIN and MAX values. And, finally using PROC PRINT to display your data results.

The SAS support website http://support.sas.com/ hosts DOC and supplemental technical papers on these and other topics. Also, the link below will connect you with the SAS-hosted product documentation for the DATA step techniques and SAS procedures.

http://support.sas.com/documentation/onlinedoc/base/

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Example

I look to an easier way. When I have only 2 animals and 3 places then it is ok. But If you have 100 animals and 10 places you must create 100 times 10 Dataset from which you find the min and then merge this to one. Thats to many datasets I find.
Super Contributor
Super Contributor
Posts: 3,174

Re: Example

I do not believe you need to split up your file into smaller files, per each animal. Review the SAS Procedures documentation and using the BY statement to generate individual descriptive statistics for each of your BY variables.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Output when more then one Conditions fulfilled

Thank you I have found the function first.
Data test1;
set test;
by var;
if first.var;
run;

This program write every first attribute from your variable in the new file.
Super Contributor
Super Contributor
Posts: 3,174

Re: Output when more then one Conditions fulfilled

I recommend not limiting yourself to the DATA step use of the BY statement, but also explore using the BY statement with SAS PROCs, as well, to generate separate analysis output based on the list of variables.

Scott Barry
SBBWorks, Inc.
Post a Question
Discussion Stats
  • 7 replies
  • 539 views
  • 0 likes
  • 2 in conversation