0
votes

I have built some macro code that passes the value in a given row of a field to a macro variable that is then used as part of a string to pull down a CSV file from a website. I've tried setting this field with a default length of $8. in a 'CALL SYMPUT' statement.

This does not work as most (but not all) of the string lengths are 4. When the code is run in the log you can see the trailing spaces in the URL being submitted to the website and the code falling over.

When I've tried it with the 'CALL SYMPUT' length of $4. it works fine on those strings that are four characters long.

This would all be alright except some character strings are one, two, three, five of six characters long. I've tried using the '%TRIM' function in the manner of %let mynewvar =%trim(&myoldvar.);' but it causes the same error where the submitted macro variable in the URL has trailing spaces...

...what am I doing wrong?

Thanks

3
Can you provide the snippet of code that uses the macro variable and forms the URL? %trim seems to work nicely for me in this simple example data null; call symput('FOO','abc '); run; %put XX&FOO.XX; %put XX%trim(&FOO.)XX; `John Leveille

3 Answers

0
votes

If you are using CALL SYMPUT() from the data step, try using the STRIP() function to remove the blanks.

data _null_;
x = "abcd    ";
call symput("x",strip(x));
run;

%put X is __&x.__;

Returns:

3735   %put X is __&x.__;
X is __abcd__
0
votes

You can try CALL SYMPUTX which left justifies and trims trailing blanks.

It would be easier to help you if we could see some sample code.