🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-28-2019 10:25 AM
(948 views)
Hello Everyone , I have this Dataset:
regions | cities | Dates |
1 | FGG | 25/01/1998 |
1 | HGT | 26/01/1998 |
1 | HJK | 27/01/1998 |
2 | LOI | . |
2 | DCF | 25/01/2001 |
2 | VG | 26/01/2001 |
2 | BBVB | 28/01/2001 |
3 | DFR | 11/07/2005 |
3 | ZAS | 12/07/2005 |
And What I want to do is , to take the mean of the Dates , when I have multiple Dates for the same region , like my output would be something like this :
regions | cities | Dates |
1 | FGG | 26/01/1998 |
1 | HGT | 26/01/1998 |
1 | HJK | 26/01/1998 |
2 | LOI | 26/01/2001 |
2 | DCF | 26/01/2001 |
2 | VG | 26/01/2001 |
2 | BBVB | 26/01/2001 |
3 | DFR | 11/07/2005 |
3 | ZAS | 11/07/2005 |
3 | EWS | 16/02/2010 |
3 | WE | 16/11/2010 |
Any Suggestion On how to do that would be much appreciated , thank you.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input regions cities $ Dates :ddmmyy10.;
format dates ddmmyy10.;
cards;
1 FGG 25/01/1998
1 HGT 26/01/1998
1 HJK 27/01/1998
2 LOI .
2 DCF 25/01/2001
2 VG 26/01/2001
2 BBVB 28/01/2001
3 DFR 11/07/2005
3 ZAS 12/07/2005
;
proc sql;
create table want1 as
select regions, cities,mean(dates) as dates format=ddmmyy10.
from have
group by regions;
quit;
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input regions cities $ Dates :ddmmyy10.;
format dates ddmmyy10.;
cards;
1 FGG 25/01/1998
1 HGT 26/01/1998
1 HJK 27/01/1998
2 LOI .
2 DCF 25/01/2001
2 VG 26/01/2001
2 BBVB 28/01/2001
3 DFR 11/07/2005
3 ZAS 12/07/2005
;
proc sql;
create table want1 as
select regions, cities,mean(dates) as dates format=ddmmyy10.
from have
group by regions;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank's a Lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First thing, is your "date" and actual SAS date value? From what you show it should be a numeric variable with format of ddmmyy10. or similar.
If not then you need to get date values and we would need to see what you have to accomplish that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In my real Dataset my dates are in Date9. Format
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your want data set has 2 obs more than your input? How does that happen?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have;
class regions;
var dates;
output out=_means_ mean=;
urn;
--
Paige Miller
Paige Miller