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

ok so, I have been working on this for a while, and I just need this last step figured out. 

I want age at the hbv test (hbv2) and I have the date of birth (CDOB). 

I do this code and get this output but obviously that isn't correct so what can I do to fix this

 

data want;
set have;
ageattest = hbv2 - CDOB;
run;

Cooksam13_0-1651269577005.png

 

 

this is proc contents for the two variables

Variable Type Len Format Informat Label

hbv2Num8YEAR.  
CDOBNum88.  
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;
ageattest = year(hbv2) - CDOB;
run;

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

View solution in original post

1 REPLY 1
Reeza
Super User
data want;
set have;
ageattest = year(hbv2) - CDOB;
run;

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

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