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

Hi,

I have a dataset in which I've created an age variable using a date of birth variable and an "age as of" variable (which I created as well), like this:

/*Calculate age from DOB*/

data want_age;

set have;

ageasof='01NOV2012'D;

run;

DATA create_age;

set want_age;

age=floor(yrdif(datepart(dob), ageasof, age));

run;

The code runs fine and seems to calculate age correctly; however, I get a message after the second step saying that Numeric values have been converted to character values. I want age to be a numeric variable, so this is problematic. However, when I run a proc contents, it says age is already numeric, and when I go to the next step which uses values of age to create age categories, I treat age as numeric and it works fine. I'm confused about why I'm getting the message re: age being converted to character values when that doesn't actually seem to be the case.

Any help is much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If you're using the third parameter to YRDIF, it should be character.  Try putting "age" in quotes inside the function.

View solution in original post

1 REPLY 1
Astounding
PROC Star

If you're using the third parameter to YRDIF, it should be character.  Try putting "age" in quotes inside the function.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1000 views
  • 0 likes
  • 2 in conversation