BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 7 replies
  • 1130 views
  • 0 likes
  • 2 in conversation