Hi All,
From the below data, I want to calculate age based on the condition like below
if age unit is year, then new_Age=age
if age unit is month, then new_age should be converted to year
if age and unit is blank, then value of new_age will be calculated by subtracting brthdtc from rficdtc .
When I write the logic, it is working but getting below message in log file. can you please help me what mistake I am doing
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
Can you please help me how to proceed. Below is the sample of data
data test; input pid age ageu $ rficdtc $19. brthdtc $10. ; cards; 101 23 Year 2012-12-09T10:51:00 1987-07-19 102 230 Mon 1999-12-11 1987-07-19 103 113 Mon 1995-12-11 1992-07-19 104 . . 2016-12-09T10:51:00 1995-07-19 ; run; proc sql; create table test1 as select pid, age, ageu, put(input(substr(strip(rficdtc),1,10),yymmdd10.),yymmdd10.) as rficdtc, strip(brthdtc) as brthdtc from test; quit; data test2; set test1; if ageu='year' THEN NEW_AGE=AGE; else if ageu='Mon' THEN NEW_AGE=round(AGE/12, 0.01); else if ageu not in ('year', 'Mon') and RFICDTC ne '' and BRTHDTC ne '' then NEW_AGE=intck('year', RFICDTC, BRTHDTC); else new_age=.; run;
the intck function takes a date not a string.
data test2;
set test1;
if ageu='Year' THEN NEW_AGE=AGE;
else if ageu='Mon' THEN NEW_AGE=round(AGE/12, 0.01);
else if ageu not in ('Year', 'Mon') and RFICDTC ne '' and BRTHDTC ne '' then NEW_AGE=intck('year', input(RFICDTC,yymmdd10.), input(BRTHDTC,yymmdd10.));
else new_age=.;
run;
also notice that strings are case sensitive. You want 'Year' not 'year'
the intck function takes a date not a string.
data test2;
set test1;
if ageu='Year' THEN NEW_AGE=AGE;
else if ageu='Mon' THEN NEW_AGE=round(AGE/12, 0.01);
else if ageu not in ('Year', 'Mon') and RFICDTC ne '' and BRTHDTC ne '' then NEW_AGE=intck('year', input(RFICDTC,yymmdd10.), input(BRTHDTC,yymmdd10.));
else new_age=.;
run;
also notice that strings are case sensitive. You want 'Year' not 'year'
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.