Hello all. i want to use trim function in statement but it gives me error.Bellow is my code. any help to solve the error is appreciated.
data afewwords;
input Word1$ Word2$ ;
cards;
*some/ WHERE
*every* THING
*no* BODY
;
select trim(word1) from afewwords ;
proc print ;run;
A lot of confusion this question has.
Like this?
data AFEWWORDS;
input WORD1 $ WORD2 $ ;
cards;
*some/ WHERE
*every* THING
*no* BODY
run;
proc sql;
select trim(WORD1) 'Word1' from AFEWWORDS ;
quit;
Word1 |
---|
*some/ |
*every* |
*no* |
A lot of confusion this question has.
Like this?
data AFEWWORDS;
input WORD1 $ WORD2 $ ;
cards;
*some/ WHERE
*every* THING
*no* BODY
run;
proc sql;
select trim(WORD1) 'Word1' from AFEWWORDS ;
quit;
Word1 |
---|
*some/ |
*every* |
*no* |
A few items to consider ...
In a DATA step, CARDS always comes last. Anything that follows the data is not part of that DATA step. The programming statements must precede the data.
While there is such a thing as a DATA step SELECT statement, it does not function the way you are trying to use it. What you are doing looks more like SELECT within PROC SQL.
If you want to print the first variable, you don't have to change the data. You can change the report instead:
proc print data=afewwords;
var word1;
run;
SAS uses fixed length character strings. So the TRIM() function will trim the trailing spaces from the value of a variable, but as soon as you put it back into a variable SAS will pad it with spaces to fill the length of the variable.
What do you want to use the TRIM() function to do? You do not need to use for normal comparisons since SAS knows that 'FRED' and 'FRED ' are the same thing.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.