SAS Programming

DATA Step, Macro, Functions and more
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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1061 views
  • 3 likes
  • 3 in conversation