DATA all_age;
SET all;
BY subject dov;
RETAIN subject;
IF first.dov THEN age=(dov-dob)/365.25;
RUN;
Hi, can someone help me figure out how to only calculate age using only the first date of visit from the first subject as there are multiple outputs per subject. And applying that age to the rest of the data for the same subject? Just a student pulling out some hair... help plz!
Based on your description,
my understanding is
DATA all_age;
SET all;
BY subject dov;
RETAIN age;
IF first.dov THEN age=(dov-dob)/365.25;
RUN;
also for some reason using the dov-dob/365 is not working with code above
You can't have missing values as an argument to yrdif as log explains YRDIF(.,14193,'actual')
If you want more help, please post a good representative sample of what you have
@rg529 wrote:
all dates are in SAS format, and the below code works, THANK YOU.DATA all_age;
SET all;
BY subject;
RETAIN age;
IF first.subject THEN age=YRDIF(dob, dov, 'actual');
RUN;BUT getting this error message in log?NOTE: Invalid argument to function YRDIF(.,14193,'actual') at line 77 column 27.subject=102 dov=14193 dbp=73 sbp=128 site=1 gender=F dob=. doe=14193 smoke=0 drink=4 marital=3 education=3 glucose=119 height=62weight=160 hdl=54 ldl=151 tg=133 tc=238 chd=1 pregnancy=0 exercise=0 FIRST.subject=1 LAST.subject=0 age=. _ERROR_=1 _N_=285
also for some reason using the dov-dob/365 is not working with code above
In that particular record, your dob is missing, so it cannot calculate an age.
if not missing(dob) then age = ...
Add an IF statement to your code to only calculate age when DOB is not missing.
@Reeza wrote:
Add an IF statement to your code to only calculate age when DOB is not missing.
For example, you could introduce the IF condition n(dob, dov)=2, which means "dob and dov are not missing":
if first.subject then do; if n(dob, dov)=2 then age= (your age formula here); else age=.; end;
Are you sure you want 'actual' as the third argument of YRDIF given that 'age' is an option designed for calculating a person's age?
Please post sample data ?
It is unclear what format your dov and dob are in are they SAS dates ?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.