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;

 

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!

SAS Enterprise Guide vs. SAS Studio

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.

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