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

Code:

 

data test;
length _character_ $25.;
infile datalines delimiter='	'; 
input
season
basin $
storm $
windrank
windmph
;
datalines;
1980	ep	agathaagatha	1	100
1980	ep	agatha	2	95
;
run;

Within the first row, the Storm value is truncated. That's because the column properties show:

 

current_thing_0-1701022965282.png

What am I doing wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

DATALINES as nothing to do with this issue.

 

The problem is this statement:

length _character_ $25.;

You are using the variable list _CHARACTER_ but at that point you have not defined any character variables, so the list is EMPTY.  The problem is that the variable has to be defined as CHARACTER to be part of the list, but once it is defined the LENGTH is already set so you cannot change it.

 

If you want to set the lengths of variables you have to actually use the names of the variables.  You can use a list of names with numeric suffixes, but not other types of variable lists.  

 

Once you have set the order of the variables you can use a positional variable list in the INPUT statement to save some typing.

data test;
  length season 8 basin storm $25 windrank windmph 8;
  input season -- windmph ;

Or you can use the fact that SAS will GUESS that you want to LENGTH of the variable match the WIDTH of a format or informat you use when the variable is first mentioned.  Just include the informat in the INPUT statement, but make sure to use the colon modifier so that the field is still read in LIST MODE.

  input season  basin :$25. storm :$25. windrank windmph ;

Also your post looks like you are trying to use space as the delimiter, but that is the default.  If you intended to use TAB as the delimiter then :

1) Use '09'x in the INFILE statement to make that CLEAR.

2) Don't do it with in-line data (datalines aka cards) because tabs can be (and probably should be) converted to spaces when included in a program.  And if you submit the code from Display Manager program editor they WILL be converted to spaces.

 

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

DATALINES as nothing to do with this issue.

 

The problem is this statement:

length _character_ $25.;

You are using the variable list _CHARACTER_ but at that point you have not defined any character variables, so the list is EMPTY.  The problem is that the variable has to be defined as CHARACTER to be part of the list, but once it is defined the LENGTH is already set so you cannot change it.

 

If you want to set the lengths of variables you have to actually use the names of the variables.  You can use a list of names with numeric suffixes, but not other types of variable lists.  

 

Once you have set the order of the variables you can use a positional variable list in the INPUT statement to save some typing.

data test;
  length season 8 basin storm $25 windrank windmph 8;
  input season -- windmph ;

Or you can use the fact that SAS will GUESS that you want to LENGTH of the variable match the WIDTH of a format or informat you use when the variable is first mentioned.  Just include the informat in the INPUT statement, but make sure to use the colon modifier so that the field is still read in LIST MODE.

  input season  basin :$25. storm :$25. windrank windmph ;

Also your post looks like you are trying to use space as the delimiter, but that is the default.  If you intended to use TAB as the delimiter then :

1) Use '09'x in the INFILE statement to make that CLEAR.

2) Don't do it with in-line data (datalines aka cards) because tabs can be (and probably should be) converted to spaces when included in a program.  And if you submit the code from Display Manager program editor they WILL be converted to spaces.

 

 

current_thing
Obsidian | Level 7
Thank you Tom! Using Length to specify individual columns worked. I did intend to use tab as delimiter because I copied from Excel. Please explain how to use '09'x in the INFILE?
current_thing
Obsidian | Level 7
Nevermind, I was typing '09x' which was causing error
Tom
Super User Tom
Super User

I usually just convert the tabs to something else that humans can see.  Like |.

It is easy if you use SAS program editor:

change '09'x '|' all

If you have to point and click through some GUI interface it is only a little harder.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 987 views
  • 1 like
  • 2 in conversation