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 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 564 views
  • 0 likes
  • 3 in conversation