/* This is example of age caluculate wihtout to display
perfect days and years in output window */
data age;
retain dob "12jun2003"d now "24may2011"d;
age1=now-dob;
age=(now-dob)/365.25;
years=int(age);
days1=round((age-years)*365.25);
months=month(now)-1;
if days1 gt 30 and months in(12,10,8,6,4,2)then do;
month1=days1/30.4375;
month=int(days1/30.4375);
if day(now)=1 then days=1;
else days=round((month1-month)*30.4375)+1;
drop days1 month1 month;
end;
else if days1 gt 30 and months in
(1,3,5,7,9,11)then do;
month1=days1/30.4375;
month=int(days1/30.4375);
if day(now)=1 then days=1;
else days=round((month1-month)
*30.4375);
drop days1 month1 month;
end;
drop age age1;
proc print data=age;
format dob now date.;
run;
Answer Posted / muralavenu
Year and Day is fine. but Month is calculating from
current month onwords(i.e. ending to starting instead of
starting to ending). How to get rid of this problem. Plz
find out.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How many data types are there in SAS?
How you are maintaining sas programmes in your company...any specific version control software you are using? If so, tell me the name?
how the sas basic syntax style described? : Sas-administrator
What does PROC print, and PROC contents do?
Explain the use of proc gplot? : sas-grid-administration
what is metadata? : Sas-bi
What function CATX syntax does?
if a variable contain dates like "2015/01"---"2015/12" (yymm) ,How to add day to those dates,if them month is jan then 31 if the month is feb then 28 so on ...
what is the different between functions and procs that calculate the same simple descriptive statistics? : Sas programming
What is the purpose of trailing @ and @@? How do you use them?
what is PhaseIII, ODS, TLG, Macro and Proc in SAS
How will you generate test data with no input data?
How do dates work in SAS data?
Give some examples where proc report’s defaults are different than proc print’s defaults?
Which are the statements whose placement in the data step is critical?