07-24-2017 11:22 AM - edited 07-24-2017 11:22 AM
I dcan't manage to use trim function in a proc sql, don't understand why.
I have a table A with a variable B which format is character(6):
I do this:
%global b; PROC SQL NOPRINT; SELECT TRIM(B) INTO :b FROM A WHERE ROW_NUMBER = 1; QUIT; %put ___&b.___;
The result in the log is:
I surely miss something, can you help me finding it?
07-24-2017 11:32 AM
proc sql noprint; select trim(" abc ") into :r from sashelp.class where name="Alfred"; quit; %put ___&r.___;
Works fine. You may also be better off using strip() function rather than trim()
07-24-2017 11:34 AM
SAS stores character variables as fixed length variables. Since you didn't tell SQL what length to make the new variable you created with the TRIM() function call its best guess was to make it the same length as the variable going into the TRIM() function. So then when you pushed the value into a macro variable it included the spaces needed to pad the trimmed value back out to the full length of the variable.
You can use the TRIMMED keyword as part of the INTO clause to remove the trailing spaces.
proc sql noprint; select b into :b trimmed from a where row_number = 1 ; quit;
Need further help from the community? Please ask a new question.