turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Code to calculate Moving Median

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 05:34 AM

Hi,

Can anyone please help me to get SAS code to calculate moving median for last 30 days.

Regards,

Swapna

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 05:48 AM

First Google hit should help (has full code):

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 05:53 AM

Hi,

Thanks for your reply.

The link which you shared is to calculate moving average and I have already gone through it..

But I am looking for a code to calculate Moving "MEDIAN" for last 30 days.

Regards.

Swapna

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 06:00 AM

Ah. maybe have a look at the expand procedure then:

(Replace MOVAVE with the MOVMED)

22104 - How can I compute a moving average of a variable?

Per:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 06:07 AM

Have gone to that option as well, and sorry to not mention that in my first post.

The challenge is we don't have SAS ETS with us, thus I need a code which should work in Base SAS.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-13-2015 09:17 AM

If you have SAS9.4 , then SQL can get that , otherwise use ARRAY.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-14-2015 12:50 AM

Hi Xia,

Yes I am having SAS 9.4, It would be really great if you can please share some sample code, so that I can try it at my end.

Regards,

Swapna

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-14-2015 12:56 AM

SAS - moving min/max using arrays

You'll notice the code was originally sourced from this website.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-14-2015 08:31 AM

OK. Here is an example :

data have; do date='01jan2014'd to today(); v=ranuni(1234); output; end; format date date9.; run; proc sql; create table want as select *,(select median(v) from have where date between a.date-30 and a.date) as moving_median_30_day from have as a; quit;

Xia Keshan

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-14-2015 11:30 AM

Just a note that the SAS SQL Median function only works in SAS 9.4

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-15-2015 08:44 AM

Thanks Reeza. I have already mentioned it before .