They are tricky to learn at first, but once you get the hang of them they can really simplify your SAS programs that deal with time-based data. Other programming languages offer complex code libraries to accomplish what these two functions can do as part of Base SAS. The INTNX (and its sister function for computing date differences, INTCK) are powerful tools for manipulating date and datetime values. You should attend the conference and see her talk in person. She has a good origin story about the 01JAN1960 date decision. I know that Marje was invited to present this talk at SAS Global Forum 2018, and I hope that I did not steal too much of her thunder. Her talk reminded me of some good practices that I was able to bring home and apply in my own production SAS jobs. It's useful for me - someone who has used SAS for a long time - to see a basic topic presented to me as if I were brand new. Marje is an excellent instructor, and she delivered a popular talk about working with SAS date values - a topic that trips up many new SAS users. I recently had the privilege of presenting at the Quebec user groups with SAS-world superstar Marje Fecht. Learning more about date and datetime intervalsįirst, an acknowledgment. Tables geo_country_code / out=country_visits_6mo Proc freq data=comm.visits ( where= (event_time > &six_mo_ago_dt ) ) I also need to remove the quotes around the interval and alignment values - the SAS macro processor will treat these as string literals and would not approve of the quotes. To express this in the SAS macro language, I need to wrap those two function calls (for the TODAY function and the INTNX function) in %SYSFUNC - the macro function that breaks out of macro processing to invoke built-in SAS functions. The form I showed above works with DATA step, but I usually capture this value in a macro variable so that I can reference it across different procedures without having to recompute it. Here's the (very long) list of built-in intervals that INTNX supports. If I wanted to go 6 years into the past, I would simply change that first argument to ' year'. 6, /* number of intervals, negative goes to the past */ 'same' /* alignment of interval date. Six_mo_ago = intnx ( 'month', /* unit of time interval */ today ( ), /* beginning date */ Here's an example that computes the date from 6 months ago: The function is called INTNX ( link to INTNX function doc). Fortunately, SAS provides a function that can compute any date - given a starting date - using just about any criteria you can imagine. I could fudge it by subtracting 183 or 184 from the value of today(), but that's not precise enough for the analytical wonks that I work with. (Because, remember, a SAS date is simply an integer representing the count of days since Jan 1, 1960.) The SAS date for "30 days ago" is simply today()-30. They answer questions such as, "what happened in the past 30 days?" or "how much activity in the past 6 months?" When I have SAS date values, going back 30 days is simple. Many of my SAS jobs are in support of date-based reports. Looking back at dates in SASīut you know who likes to look at the past? Managers (and probably a few of my colleagues.). I live in the present and I look towards the future - as all citizens of the world should. Weren't my kids so cute back then? It's true, they were - but I don't pine for those days. Sometimes it works and I share them with friends. They think, "We have a collection of photos from this month/day from some previous year - let's collect those together and then prey on Chris' nostalgia instincts." These apps are performing the simplest of date-based math to trick me. Every day, my view of Google Photos or Facebook shows me a collection of photos from exactly some number of years ago to remind me of how good things were back then. Social media has brought anniversary dates to the forefront.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |