/**********************************************************************/
/* Example 1 - Creating a SAS date from a numeric value */
data one;
x=122595;
charx=put(x,z6.);
datex=input(charx,mmddyy6.);
run;
proc print;
format datex mmddyy10.;
run;
/**********************************************************************/
/* Example 2 - Storing the calendar date of a SAS date in a */
/* variable */
data one;
x='25dec95'd;
new1=put(x,monyy7.);
new2=put(x,weekdate17.);
run;
proc print;
run;
/**********************************************************************/
/* Example 3 - Computing the week of the year for a SAS date */
data one;
input date date7.;
weekofyr=intck('week',intnx('year',date,0),date)+1;
cards;
01mar94
15jan95
;
run;
proc print;
format date date7.;
run;
/**********************************************************************/
/* Example 4 - Computing a person's age */
data birth;
input name $ bday date9.;
cards;
Joe 02sep1985
John 31jan1993
Amy 16jan1984
Susan 12feb1967
Michael 14nov1975
Lee 04jul1990
Sally 27apr91
;
data ages;
set birth;
current=today();
format current bday worddate20.;
age=int(intck('month',bday,current)/12);
if month(bday)=month(current) then
age=age-(day(bday)>day(current));
run;
/**********************************************************************/
/* Example 5 - Changing formats of time values to be in */
/* using TIMEw. */
data time1;
input timechar $11.;
cards;
55.34
10:00:00.45
5:23.77
7:22:45.45
;
proc format;
picture tme other='99:99:99.99' ;
run;
data time2(drop=tmp1 tmp2);
format sastime time11.2;
set time1;
tmp1=compress(timechar,':');
tmp2=put(input(tmp1,11.2),tme.);
sastime=input(tmp2,time11.);
run;
/**********************************************************************/
/* Example 6 - Reading time values with 'AM' and 'PM' in the */
/* time */
data one(drop=check);
input timeval $10.;
check=indexc(timeval,'a','p');
newtime=input(substr(timeval,1,check-1),time8.);
if substr(timeval,check,1)='p' then
newtime=newtime+43200;
format newtime time8.;
cards;
10:25:10am
3:30:30pm
8:13:00am
10:15:00pm
;
run;
/**********************************************************************/
/* Example 7 - Creating a SAS datetime value from a SAS date */
/* and time */
data one;
input strtdt mmddyy8. strttm time.;
cards;
01/01/96 10:23:35
06/21/95 12:30:00
07/06/95 07:15:22
04/27/96 17:35:42
;
data two;
set one;
datetm=dhms(strtdt,0,0,strttm);
format strtdt mmddyy8. strttm time8. datetm datetime.;
run;
/**********************************************************************/