- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
Minor question, I was just testing to see if the 'options' on TRIM would work for me in a project.
I see options 'Both | leading | trailing', I had never used an option with trim before so I tried it and so far cannot get anything to work but the default no option. Just curious. ?? Any chance this is obsolete document?
Example
Table: AFEWWORDS
The following statements illustrate the TRIM function:
Statements
Results
select trim(word1) from afewwords;
*some/
*every*
*no*
select trim(both '*' from word1) from afewwords;
some
every
no
select trim(leading '*' from word1) from afewwords;
some/
every*
no*
select trim(trailing '*' from word1) from afewwords;
*some/
*every
*no
data AfewWords;
infile datalines dlm=',';
input Word1 & $10. Word2 $15.;
datalines;
*some/ , WHERE
*every* , THING
*no* , BODY
*no* , BODY body
;
proc print data=AfewWords;run;
proc sql;
select trim(word1) as trim_word1_exp1 from AfewWords
;quit;
/*
The above works, the below fails??
*/
proc sql;
select trim(both '*' from word1) as trim_word1_exp2 from AfewWords
;quit;
PS It seems that many of the SAS provided examples are very roughly written and leave a lot to the user or do not work.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to use PROC FEDSQL to use that version of TRIM().
data AfewWords;
infile datalines dlm=',';
input Word1 & $10. Word2 $15.;
datalines;
*some/ , WHERE
*every* , THING
*no* , BODY
*no* , BODY body
;
proc fedsql;
select *
, trim(word1) as trim_word1_exp1
, trim(both '*' from word1) as trim_word1_exp2
, trim(both '*' from trim(word1)) as trim_word1_exp3
from AfewWords
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Note that you're in the FEDSQL documentation. You likely want the main SAS documentation instead, this doesn't apply to you.
@kjohnsonm wrote:
Hello all,
Minor question, I was just testing to see if the 'options' on TRIM would work for me in a project.
I see options 'Both | leading | trailing', I had never used an option with trim before so I tried it and so far cannot get anything to work but the default no option. Just curious. ?? Any chance this is obsolete document?
Example
Table: AFEWWORDS
The following statements illustrate the TRIM function:
Statements
Results
select trim(word1) from afewwords;
*some/
*every*
*no*
select trim(both '*' from word1) from afewwords;
some
every
no
select trim(leading '*' from word1) from afewwords;
some/
every*
no*
select trim(trailing '*' from word1) from afewwords;
*some/
*every
*nodata AfewWords; infile datalines dlm=','; input Word1 & $10. Word2 $15.; datalines; *some/ , WHERE *every* , THING *no* , BODY *no* , BODY body ; proc print data=AfewWords;run; proc sql; select trim(word1) as trim_word1_exp1 from AfewWords ;quit; /* The above works, the below fails?? */ proc sql; select trim(both '*' from word1) as trim_word1_exp2 from AfewWords ;quit;
PS It seems that many of the SAS provided examples are very roughly written and leave a lot to the user or do not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to use PROC FEDSQL to use that version of TRIM().
data AfewWords;
infile datalines dlm=',';
input Word1 & $10. Word2 $15.;
datalines;
*some/ , WHERE
*every* , THING
*no* , BODY
*no* , BODY body
;
proc fedsql;
select *
, trim(word1) as trim_word1_exp1
, trim(both '*' from word1) as trim_word1_exp2
, trim(both '*' from trim(word1)) as trim_word1_exp3
from AfewWords
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Tom, I normally just google SAS and the key word/command I want to use. I feel a bit silly now. Thank you for the pointer, I had no idea there was a fedsql. -thanks.
However in my defense when I search for “sas 'proc sql' trim” no double quotes the number one hit is the fedsql version, the third hit is the proc sql' version to the documents. d'oh