The SAS Output Delivery System and reporting techniques

Problem to remove trailing blanks

Reply
N/A
Posts: 0

Problem to remove trailing blanks

Hi,

Not able to remove trailing blanks from repnum variable.

Piece of code:-

%LET project= XY_ABCD0021_XXXX;
%GLOBAL project repnum business ;
DATA _NULL_;
repnum=substr("&project",1,11);
business=substr("&project",1,2);
CALL SYMPUT("repnum",repnum);
CALL SYMPUT("business",business);
RUN;


FILENAME outfile "c:\test\&repnum..txt";

PROC PRINTTO FILE=outfile NEW;
RUN;

In this piece code I want to create text file with the name XY_ABCD0021.txt
But when I ran this code my file name is saved with trailing blanks after XY_ABCD0021
.txt

So can you give me any solution so that i can remove these trailing blanks.

Message was edited by: Sunil Gandhi Message was edited by: Sunil Gandhi
SAS Super FREQ
Posts: 8,864

Re: Problem to remove trailing blanks

Posted in reply to deleted_user
Hi:
This is not really an ODS or reporting procedure question. However, when you use the DATA step and CALL SYMPUT to make your macro variables, you are responsible for trimming the data step variables yourself.

My preferred method is to just use %SUBSTR and the %LET -- which the macro facility usually trims for you. Compare the LOG (and the %PUT output) for both of these examples. For more help with the Macro coding, contact Tech Suport.

cynthia
[pre]
*** 1) only use %LET and %SUBSTR;
*** use %LET statement and NOT datastep;
*** %LET will strip trailing blanks for you;

%LET project= XY_ABCD0021_XXXX;
%GLOBAL project repnum business ;
%put ------->;
%let repnum = %substr(&project,1,11);
%put &repnum;
%let business = %substr(&project,1,2);
%put &business;

%let newname = &repnum..txt;
%put &newname (without any "trim");
%put ------->;

FILENAME outfile "c:\temp\&repnum..txt";

PROC PRINTTO FILE=outfile NEW;
RUN;

proc print data=sashelp.class;
title "will be saved to &repnum..txt";
run;

proc printto; run;

*** 2) Use DATA step and SYMPUT, but use TRIM function, too.;
%LET project= ZZ_ZYXW0042_AAAA;

DATA _NULL_;
repnum2=substr("&project",1,11);
business2=substr("&project",1,2);
CALL SYMPUT("repnum2",trim(repnum2));
CALL SYMPUT("business2",trim(business2));
RUN;

%put -------> using trim function with call symput;

%put &repnum2;

%put &business2;

%let newname2 = &repnum2..txt;
%put &newname2 (with "trim" and call symput);
%put ------->;

FILENAME outfile2 "c:\temp\&repnum2..txt";

PROC PRINTTO FILE=outfile2 NEW;
RUN;

proc print data=sashelp.class;
title "will be saved to &repnum2..txt";
run;

proc printto; run;

[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 126 views
  • 0 likes
  • 2 in conversation