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

Hello

This code is creating a shell empty data set .

What is the difference between these 2 ways? value 8 or value 10??? both are numeric....

 


data want1;
format date date9. value 8.;
stop;
run;


data want2;
format date date9. value 10.;
stop;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Let's step through each line in the data step an see what it is you asked SAS to do.

data want1;

So this says the data step is going to create the work dataset named WANT1.

format date date9. value 8.;

This line is attaching display formats to two variables.  Since neither variable has yet been defined the data step compiler will GUESS that you wanted them defined as numeric variables since you are attaching numeric formats to them.

stop;

This is only executable statement in the data step.  It tells the data step to stop running, which prevents it from executing the automatic OUTPUT statement that will run in any data step that does not contain an explicit output statement.

 

So the only difference between the two is that in one you told SAS to use 8 characters to display the variable named VALUE and the other you told it that it should display it with 10 characters instead.

 

So both datasets will have the same variable names, same variable types and the only difference is the display format that is attached.  Note that there is no need to attach formats to normal numeric variables, SAS will automatically use the BEST12. format in most places when the variable does not have any format attached.  The same with character variables, there is no need to attach the $ format to character variable because the default behavior is to display the full value of the character variable.

 

If you want to avoid forcing SAS to GUESS how to define the variables then define them before using them in statements (like FORMAT, INFORMAT, assignment statements, ARRAY, etc.)  that will require that SAS knows the variables type.  For example using LENGTH statement.  Then you only need to use the FORMAT statement to attach formats to the variables that need them.

data want1;
  stop;
  length date value 8 ;
  format date date9. ;
run;

 

View solution in original post

2 REPLIES 2
ballardw
Super User

The difference will be in the default way that values are displayed. By default neither will display decimals for the variable Value because you have not provided any in the format (the .d part of w.d in the format) If you have a value that uses more than 8 positions, such as 123456789, then the value will be displayed in scientific notation such as 1.2346E8 as that is the closest that can be displayed with 8 positions. Use of the 10. format means values greater than 10 digits would be displayed in scientific notation.  

Do not that the VALUE of the variable doesn't change, just the default display behavior like any format.

Tom
Super User Tom
Super User

Let's step through each line in the data step an see what it is you asked SAS to do.

data want1;

So this says the data step is going to create the work dataset named WANT1.

format date date9. value 8.;

This line is attaching display formats to two variables.  Since neither variable has yet been defined the data step compiler will GUESS that you wanted them defined as numeric variables since you are attaching numeric formats to them.

stop;

This is only executable statement in the data step.  It tells the data step to stop running, which prevents it from executing the automatic OUTPUT statement that will run in any data step that does not contain an explicit output statement.

 

So the only difference between the two is that in one you told SAS to use 8 characters to display the variable named VALUE and the other you told it that it should display it with 10 characters instead.

 

So both datasets will have the same variable names, same variable types and the only difference is the display format that is attached.  Note that there is no need to attach formats to normal numeric variables, SAS will automatically use the BEST12. format in most places when the variable does not have any format attached.  The same with character variables, there is no need to attach the $ format to character variable because the default behavior is to display the full value of the character variable.

 

If you want to avoid forcing SAS to GUESS how to define the variables then define them before using them in statements (like FORMAT, INFORMAT, assignment statements, ARRAY, etc.)  that will require that SAS knows the variables type.  For example using LENGTH statement.  Then you only need to use the FORMAT statement to attach formats to the variables that need them.

data want1;
  stop;
  length date value 8 ;
  format date date9. ;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 739 views
  • 2 likes
  • 3 in conversation