Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How sas is used as a function of time

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how sas is used in the function of time, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

When dealing with stock data, we often have to deal with time variables and specially extract the samples of sas.support.com to learn the function of sas for time. There are also many detailed examples in the article "DATE HANDLING IN THE SAS ®SYSTEM".

* calculate the age; / * Create sample data * / data birth; input name $bday: mmddyy10.;datalines;Miguel 12/31/1973Joe 02/28/1976Rutger 03/29/1976Broguen 03/01/1976Susan 12/12/1976Michael 02/14/1971LeCe 11/09/1967Hans 07/02/1955Lou 07, Use the INTCK function to count the number of months between, 30, and 1960, the date of birth and the current date. Divide the number of * / * months by 12 to produce the number of years. Use the MONTH * / * function to determine if the month of the birthday and the current * / / * date are the same. If they are, determine if the birthday has * / * occurred this year. If it hasn't, adjust the age by subtracting * / * one year. * / data ages; set birth; retain current; if _ nasty days 1 then current=today (); format bday current worddate20.; age=int (intck ('month',bday,current) / 12); if month (bday) = month (current) then age=age- (day (bday) > day (current)); run;proc print;run;* calculates the number of years, months and days between two days; data a; input @ 1 dob mmddyy10.; / * Get the current date from operating system * / tod=today () / * Determine number of days in the month prior to current month * / bdays=day (intnx ('month',tod,0)-1); / * Find difference in days, months, and years between * / / * start and end dates * / dd=day (tod)-day (dob); mm=month (tod)-month (dob); yy=year (tod)-year (dob) / * If the difference in days is a negative value, add the number * / / * of days in the previous month and reduce the number of months * / / * by 1. * / if dd < 0 then do; dd=bdays+dd; mm=mm-1; end / * If the difference in months is a negative number add 12 * / / * to the month count and reduce year count by 1. * / if mm < 0 then do; mm=mm+12; yy=yy-1; end; format dob tod mmddyy10.;datalines;01/01/197002/28/199201/01/200002/28/200002/29/200003/01/200005/10/199005/11/199005/12/1990;proc print label Label dob='Date of Birth' tod= "Today's Date" dd='Difference in Days' mm= 'Difference in Months' yy='Difference in Years'; var dob tod yy mm dd;run / * / * The following code calculates the start and end dates for * / / * daylight saving time for the years 2006 through 2009. * / / * * / * FDOY represents the first day of the year * / / * FDO_APR represents the first day of April * / / * DST_BEG represents the first day of daylight saving time * / / * * / * It is calculated using this syntax: * / / * intnx ('week.1' Fdo_apr, (weekday (fdo_apr) ne 1)) * / * * / / * Explanation of the above syntax: * / *-weekday (fdo_apr) returns a number between 1 and 7, * / / * which represents the day of the week 1=Sunday and 7=Saturday * / / * * / *-weekday (fdo_apr) ne 1) returns a 0 if the first day * / / * of April is a Sunday and 1 otherwise. * / / * * / *-intnx ('week.1',fdo_apr, (weekday (fdo_apr) ne 1)) returns a * / / * SAS date which is 0 WEEK intervals from the FDO_APR, if the * / * first day of April is a Sunday. The WEEK.1 interval specifies * / * Sunday as the first day of the week. * / / * * / * OR * / / * * / / * returns a SAS date which is 1 WEEK interval from the FDO_APR * / * if the first day of April is not a Sunday, (using Sunday as * / / * the first day of the week). * / * DST_END represents the end of daylight saving time and is * / / * calculated similarly to DST_BEG. * / / * / data _ null_; do year=2006 to 2009; fdoy=mdy (1 For years prior to 1 year); / * For years prior to 2007, daylight time begins in the United States on * / / * year. * / if year

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report