BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I am not able to use the format Year or may be I don't use it properly.

 

data test;
yearstr='2024';
year=input(yearstr, year4.);
run;

 

29 data test;
30 yearstr='2024';
31 year=input(yearstr, year4.);
______
485
NOTE 485-185: Informat YEAR was not found or could not be loaded.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

With INPUT you are attempting to use an INFORMAT, not Format, typically converting text to numeric.

If you are attempting to create a date variable you would need to provide more information, likely as a longer string and a different Informat or use the MDY function to impute a month and day to go along with your yearstr converted to numeric. Year4. exists as a date format to display just the year portion of a date in 4 digits. While many date formats have a corresponding informat this in not one of them.

 

The following code creates a date using imputed month of 1, January, and day of month 1 to create a date of 1Jan2024. Then assign the date format YEAR4. as the default display format.

data test;
yearstr='2024';
year=mdy(1,1, input(yearstr, 4.));
format year year4.; /* to use the FORMAT Year*/
run;

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

There is no informat YEAR.

 

You can just convert '2024' to a number with the 4. informat. Of course, this brings up the question why 2024 is a character string, years should be numeric!

--
Paige Miller
alepage
Barite | Level 11
How do we use year4.
Tom
Super User Tom
Super User

@alepage wrote:
How do we use year4.

You can use the YEAR4. format specification with a numeric variable that contains date values.

Example:

data test;
   today=date();
   today_year = today;
   year_number=year(today);
   year_string=put(today,year4.);
   format today yymmdd10. today_year year4. ;
run;

Tom_0-1725911414673.png

 

Remember:  FORMATS convert values into TEXT.  INFORMATS convert TEXT into values.

ballardw
Super User

With INPUT you are attempting to use an INFORMAT, not Format, typically converting text to numeric.

If you are attempting to create a date variable you would need to provide more information, likely as a longer string and a different Informat or use the MDY function to impute a month and day to go along with your yearstr converted to numeric. Year4. exists as a date format to display just the year portion of a date in 4 digits. While many date formats have a corresponding informat this in not one of them.

 

The following code creates a date using imputed month of 1, January, and day of month 1 to create a date of 1Jan2024. Then assign the date format YEAR4. as the default display format.

data test;
yearstr='2024';
year=mdy(1,1, input(yearstr, 4.));
format year year4.; /* to use the FORMAT Year*/
run;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 1107 views
  • 3 likes
  • 4 in conversation