BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fatemeh
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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*

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

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*
Astounding
PROC Star

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;

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1160 views
  • 3 likes
  • 4 in conversation