Hi,
In the query builder I added a computed column to add a year (2024) to the data set. But when I run the changes I get the output 1965 instead of 2024.
Computed item: PUT(YEAR(2024), 4.)
I really need it to be in date format and not a numeric format that's why I used the calculated item above.
What do I have to do differently?
Many thanks in advance!
@user34567 wrote:
Exactly, but I need it to be a date format YYYY, not numeric
A DATE is numeric. But the number 2,024 is a day in July of 1965. So applying the YEAR() function or the YEAR format to the value 2,024 will yield 1965.
Assign and actual date to your new variable. Then attach a format, like YEAR4. that just displays the year part of the date value.
If VIYA supports SAS date constants use:
'01JAN2024'd
If you have a variable whose value is the number 2024, you don't need to format it and you don't need to use it inside PUT(). You can simply use the variable which has the value of 2024.
Please explain further, show us the inputs and the desired output. What does it mean to "add a year to a data set"? SHOW US.
Hi @PaigeMiller, thank you for responding. If I just add "2024" it wel be marked as a numeric value instead of date. In SAS Viya I would like to link the years from two different datasets to eachother but I cannot do that when it is not seen as a real date.
Exactly, but I need it to be a date format YYYY, not numeric
Stop referring to formats here. SHOW US what you have at the start and then SHOW US the desired end result.
????
@user34567 wrote:
Exactly, but I need it to be a date format YYYY, not numeric
A date in SAS is always numeric (count of days starting at 1960-10-01), which is displayed in human-readable form through a format of the date group.
The YEAR. format will display only the year part of such a value.
So, what do you have in both datasets (type and format of the existing variables), and along which value extracted from these do you want to join?
@user34567 wrote:
Exactly, but I need it to be a date format YYYY, not numeric
A DATE is numeric. But the number 2,024 is a day in July of 1965. So applying the YEAR() function or the YEAR format to the value 2,024 will yield 1965.
Assign and actual date to your new variable. Then attach a format, like YEAR4. that just displays the year part of the date value.
If VIYA supports SAS date constants use:
'01JAN2024'd
Thank you, this was very helpful! Now I also understand why my 'solution' was not working.
@user34567 wrote:
Hi @PaigeMiller, thank you for responding. If I just add "2024" it wel be marked as a numeric value instead of date. In SAS Viya I would like to link the years from two different datasets to eachother but I cannot do that when it is not seen as a real date.
If you want to create a DATE value you need to specify the month and the day also. Normally people just use January 1st.
@user34567 wrote:
Hi,
In the query builder I added a computed column to add a year (2024) to the data set. But when I run the changes I get the output 1965 instead of 2024.
Computed item: PUT(YEAR(2024), 4.)
I really need it to be in date format and not a numeric format that's why I used the calculated item above.
What do I have to do differently?
Many thanks in advance!
Do not use a calculated item.
Change the format on the variable to be YY4. YEAR4. instead.
https://documentation.sas.com/doc/da/vdmmlcdc/8.1/leforinforref/p0jwqba6i1r0j1n1xe9ovnn0pamr.htm
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.