Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS Proc SQL Trim not working?

Tags:

trim

sas

proc-sql

I have a problem that seems pretty simple (probably is...) but I can't get it to work.

The variable 'name' in the dataset 'list' has a length of 20. I wish to conditionally select values into a macro variable, but often the desired value is less than the assigned length. This leaves trailing blanks at the end, which I cannot have as they disrupt future calls of the macro variable.

I've tried trim, compress, btrim, left(trim, and other solutions but nothing seems to give me what I want (which is 'Joe' with no blanks). This seems like it should be easier than it is..... Help.

data list;
    length id 8 name $20;
    input id name $;
cards;
1 reallylongname
2 Joe
;
run;

proc sql;
    select trim(name) into :nameselected
    from list
    where id=2;
run;

%put ....&nameselected....;
like image 607
pyll Avatar asked Dec 01 '22 00:12

pyll


2 Answers

Actually, there is an option, TRIMMED, to do what you want.

proc sql noprint;
    select name into :nameselected TRIMMED
    from list
    where id=2;
quit;

Also, end PROC SQL with QUIT;, not RUN;.

like image 188
DomPazz Avatar answered Dec 05 '22 16:12

DomPazz


It works if you specify a separator:

proc sql;
    select trim(name) into :nameselected separated by ''
    from list
    where id=2;
run;
like image 38
Jeff Avatar answered Dec 05 '22 17:12

Jeff