Tag: SAS

Installing SAS Viya 4 (2021.1.2) Locally

I have been wanting to get SAS® Viya 4 running locally on our lab hardware to further investigate the REST APIs, and having just finished the installation, I thought I’d jot down a few notes. SAS Viya 4 has initially been released for the ma…

SAS Management Console on HiDPI Windows 10 Revisited

It has been a few years since I posted SAS Management Console on HiDPI Windows 10, and the Windows 10 HiDPI options have changed a little since then, so I wanted to post an update. Compared to the simple Override high DPI combo box from 2017, there is …

Metacoda Plug-ins Tip: View SAS Management Console Log File

In supporting Metacoda Plug-ins, one of the most useful things for us to review is the SAS Management Console log file SASMCErrorLog.txt. If you have ever had to look at this file yourself, or ask someone to email you a copy, then you would know it can…

When SAS Management Console Fails to Start

It is very rare, but occasionally, such as after an update, SAS® Management Console may fail to start. It is so rare for me that next time it happens I have usually forgotten what I did last time to fix it – hence this post. Whenever I have …

Estimating birth date from age

This code demonstrates an algorithm for estimating birth date from age. We cannot know the exact birth date, but we can get close: the maximum error is half a year, and the typical error is one quarter of a year.



/* The %age macro was taken from the Internet---maybe from here http://support.sas.com/kb/24/808.html ? */
%macro age(date,birth);
floor ((intck('month',&birth,&date) - (day(&date) %mend age;

/*
Generate 10000 fake people with random birth dates and random perspective days
on which their age was measured. Then, calculate age from that perspective date.
In reality, there is some seasonality to births (e.g., more births in July), but
here we assume each day of the year has an equal distribution of births.
*/
data person;
format birth_date submit_date yymmdd10.;
do i = 1 to 10000;
birth_date = %randbetween(19000,20500);
submit_date = birth_date + %randbetween(0,100*365);
age = %age(submit_date, birth_date);
output;
end;
drop i;
%runquit;

/* Work in reverse from age to estimated birth date. */
data reverse;
set person;
format birth_date_min birth_date_max yymmdd10.;
birth_date_min = intnx('years', submit_date, -1 * (age+1), 's') - 1;
birth_date_max = intnx('years',birth_date_min,1,'s') + 1;

/* check range of estimates for errors */
min_error = (birth_date > birth_date_min);
max_error = (birth_date < birth_date_max);

/* estimate birth date as the middle of the range */
birth_date_avg = mean(birth_date_min, birth_date_max);

/* calculate variance */
abs_days_error = abs(birth_date - birth_date_avg);
%runquit;

/* Both errors should always be zero. */
proc freq data=reverse;
table min_error max_error;
quit;

/* Error of estimates range from 0 to 183.5 with a median of 92 and average of 91.*/
proc means data=reverse n nmiss min median mean max;
var abs_days_error;
quit;

/* Distribution of errors is uniform */
proc sgplot data=reverse;
histogram abs_days_error;
quit;

Tested with SAS 9.4M6

For more posts like this, see Heuristic Andrew.

Ignore This Blog Post

The Little SAS Book, Sixth Edition is now a year old.  I have already written posts about What’s New in this edition, and the very cool XLSX LIBNAME engine.  So what more is there to say?  A lot, it turns out.  The Sixth Edition was our biggest rewrite since the Second Edition introduced the new […]