0

When I run some simple code to create a variable using the strip function, it properly strips leading and trailing blanks. However, when I call the program the code is in with a %include. It doesn't work.

data aniorder;
    input animalname $ seq taxonomy $20.;
    datalines;
    DOG 1 800
    ELEPHANT 2 0
    FISH 3 0
    ;
run;
data aniorder2;
    set aniorder;
ani = strip(animalname);
keep ani seq taxonomy;
run;

When running %include, I don't get an error message, but the variable "ani" on the aniorder2 dataset still has the leading and trailing blanks. This doesn't happen when I just run the code above.

Anyone have any idea what's happening with %include here?

1 Answer 1

1

Variables will ALWAYS have trailing blanks. SAS character variables are fixed length and padded with blanks. But the STRIP() function call will definitely remove leading blanks, but there should not be any leading blanks given the informat used in your input statement.

Perhaps your source file has the wrong end of line characters? For example if you made the file on a PC it would normally have CR+LF at the end of each line. If you then read that file on Unix the CR would become part of the data for the line. And since your posted example as leading spaces on the data lines (why are those there?) perhaps you saved the file using TAB characters to replace some of the blank characters?

Try adjusting your program. You could try adding the / TERMSTR=CRLF option to the %INCLUDE statement and see if that eliminates the trailing "blanks". You could try adding an INFILE statement so that you can include the EXPANDTABS and see if that eliminates the leading "blanks". You could also add the TRUNCOVER option since you are reading more characters than are on the lines. Not sure if it is needed since normally in-line data is padded automatically to a multiple of 80 characters.

data aniorder;
  infile datalines expandtabs truncover ;
  input animalname $ seq taxonomy $20.;
datalines;
DOG 1 800
ELEPHANT 2 0
FISH 3 0
;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Tom! It was as simple as getting rid of the TAB characters on the data lines.
Yet another example of why you should not store actual TAB characters in source code files. If you are using the SAS Display Manager editors you can change the settings to have it replace tabs with spaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.