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:
What am I doing wrong?
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.
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.