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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.