BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kjohnsonm
Lapis Lazuli | Level 10

Hello all,

Minor question, I was just testing to see if the 'options' on TRIM would work for me in a project.  


http://support.sas.com/documentation/cdl/en/fedsqlref/67364/HTML/default/viewer.htm#n1x15ai82patq8n1...


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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

image.png

View solution in original post

3 REPLIES 3
Reeza
Super User

Note that you're in the FEDSQL documentation. You likely want the main SAS documentation instead, this doesn't apply to you.

 

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lefunctionsref&docsetTarg...

 


@kjohnsonm wrote:

Hello all,

Minor question, I was just testing to see if the 'options' on TRIM would work for me in a project.  


http://support.sas.com/documentation/cdl/en/fedsqlref/67364/HTML/default/viewer.htm#n1x15ai82patq8n1...


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.


 

Tom
Super User Tom
Super User

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;

image.png

kjohnsonm
Lapis Lazuli | Level 10

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1188 views
  • 3 likes
  • 3 in conversation