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

Why set format 4.1 in the program, when input 8, the result is 0.8, input 8.0, the result is 8. I'm a little confused by this logic, please help me~

cheche_0-1733808606825.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Those results are to be expected. Why the author might want those results is anybody guess. But they are expected.
Let's examine what the 4.1 informat means. First, it means "read 4 characters." Second, inspect those four characters to see if they contain a decimal point. If a decimal point is found, use it. Third, 4.1 means if no decimal point appears in the 4 characters, assume 1 character belongs after the decimal point.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Your 4.1 in an INPUT statement is an INformat, not a format. It tells SAS how to read the numbers. If you want to tell SAS how to display (or write to an output) the numbers, then you need a format. This allows numbers to read in a certain way, and displayed (or written to an output) differently, if so desired.

 

data a;
    input source 4.1;
    format source 4.1;
    cards;
...
;

 

--
Paige Miller
cheche
Calcite | Level 5
thank you
Astounding
PROC Star
Those results are to be expected. Why the author might want those results is anybody guess. But they are expected.
Let's examine what the 4.1 informat means. First, it means "read 4 characters." Second, inspect those four characters to see if they contain a decimal point. If a decimal point is found, use it. Third, 4.1 means if no decimal point appears in the 4 characters, assume 1 character belongs after the decimal point.
cheche
Calcite | Level 5

I got it. Thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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