Learning SAS? Welcome to the exclusive online community for all SAS learners.

Not able to change length of numeric variable using colon modifier

Reply
Occasional Contributor
Posts: 17

Not able to change length of numeric variable using colon modifier

     Hello All,

I am not able to change the length of numeric variable using colon modifier.

Following is my code:

data sample;

     *length X 5;

     input X : 5.;

  datalines;

1

2

3

;

run;

proc contents data = sample;

run;

I am able to change the length using length statement but not without it.

Please Help

Super User
Super User
Posts: 7,962

Re: Not able to change length of numeric variable using colon modifier

Posted in reply to gurpreetkaur

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.

Super Contributor
Posts: 308

Re: Not able to change length of numeric variable using colon modifier

Posted in reply to gurpreetkaur

Hello,

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.

data havee;

input a :2. b;

datalines;

123434456 4

;


Contributor
Posts: 45

Re: Not able to change length of numeric variable using colon modifier

Hi,

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.

Super User
Super User
Posts: 7,050

Re: Not able to change length of numeric variable using colon modifier

Posted in reply to gurpreetkaur

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.

Ask a Question
Discussion stats
  • 4 replies
  • 418 views
  • 0 likes
  • 5 in conversation