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

Hello,

 

I have a problem with something that should be very simple:

 

I have two variables that are both years. The first one is year4 format, and the second one is BEST12.

 

All I want is to make a new variable that is these two years substracted from each other, but I just get a wierd number that I can't explain.

 

I have tried making the BEST12 years into year4 format, but then they all become 1965, I have no idea why!

 

What can I do?

 

I have also tried the other way around without luck.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @NLIL  I would assume a variable showing a year value with yearw. format is actually a SAS date value rather. Therefore to compute difference in years, you would need to extract year from the SAS date value i.e year(diag_year) and then subtract

 

So

diag_age = year(diag_year) - birth_year;

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

@NLIL hi and welcome to the SAS Community 🙂

 

Can you show us an example?

NLIL
Calcite | Level 5

Thanks!

 

The first variable in year4. format:

 

Diag_year

2000

1995

2003

and so on...

 

Next variable in best12 format:

 

birth_year:

1996

1987

2000

and so on

 

I just want to say:

 

diag_age = diag_year - birth_year;

novinosrin
Tourmaline | Level 20

Hi @NLIL  I would assume a variable showing a year value with yearw. format is actually a SAS date value rather. Therefore to compute difference in years, you would need to extract year from the SAS date value i.e year(diag_year) and then subtract

 

So

diag_age = year(diag_year) - birth_year;

 

NLIL
Calcite | Level 5

THANK YOU! Heart

novinosrin
Tourmaline | Level 20

You're welcome 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1544 views
  • 0 likes
  • 3 in conversation