01-13-2015 06:55 AM
I am not able to change the length of numeric variable using colon modifier.
Following is my code:
*length X 5;
input X : 5.;
proc contents data = sample;
I am able to change the length using length statement but not without it.
01-13-2015 06:59 AM
I do not see what the issue is. SAS as default assigns length 8 to any numeric variable unless you *explicitly* set it to seomthing else, e.g. with a length statement. You input statement does not affect the output data, it only affects the data as it is read in. I.e. the input statement reads the datalines information in the format 5., and this goes out to your dataset as X length =8 which is SAS default.
This is expected and proper execution.
01-13-2015 08:16 AM
In case of reading numeric variables with modified list input, SAS ignores what you specify after the colon modifier.
Consider the following example, where you can notice how SAS reads the varible a until it encounters a blank.
input a :2. b;
01-13-2015 09:52 AM
As RW9 already mentioned, the SAS default lenght for numeric variables is 8 and sufficient for programming purposes.
Now, it might be helpful if you could tell us what you would like to to accomplish. I have a hunch that you are more concerned about how the numeric data is dsiplayed in a report and, if so, a format would be more appropriate.
01-13-2015 06:50 PM
The FORMAT you use to read a variable is not a reliable way to define the storage LENGTH for the variable.
The storage LENGTH for a number should normally be 8 unless you are positive that your values will not be impacted by SAS storing an 8 bytes floating point value in less than 8 bytes of storage. SAS(R) 9.2 Companion for Windows, Second Edition
If you want to effect the way that your numbers are displayed then use a FORMAT statement. If you do it within the data step that creates the dataset then the format is attached the variable and will be used in future code unless overridden by another FORMAT statement.