BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
abraham1
Obsidian | Level 7

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;





1 ACCEPTED SOLUTION

Accepted Solutions
rudfaden
Lapis Lazuli | Level 10

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'

View solution in original post

1 REPLY 1
rudfaden
Lapis Lazuli | Level 10

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'

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 909 views
  • 1 like
  • 2 in conversation