- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Team
I am running the below code and am getting space in the output. The &comp. is the global variable.
Is there any way that we can remove the space at the output.
data _null_;
set &outdat.;
file "&drv2./test/Current/&benpk._&comp._00.txt" ls = 4000 mod;
put '"' name +(-1) '",'
'"' fname +(-1) '",'
'"'zip +(-1) '",'
run;
E_42 _00.txt
NEED:
E_42_00.txt
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
HOW do you create &comp? An unwanted space would mean the approach to creating it needs to be addressed. Prevent not fix is a better approach.
The %trim macro function might work unless the "space" shown in the name is a different null character.
%let comp=%trim(&comp.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If COMP just has an regular space without macro quoting it is much easier to just use the %LET statement itself to remove the trailing/leading spaces.
%let comp=∁
I don't really like to use %TRIM() as it is an autocall macro and not an actual macro function. So if someone has accidentally left the SYMBOLGEN and/or MLOGIC options turned on your SAS log can get cluttered with a lot of extra lines depending on the number of trailing spaces it has to remove.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there any option to change the output text file name from SAS data step ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The TRIM() function works on actual variables or strings. Not on macro variables. And if you assign the result back to a variable then the spaces will return if the result is shorter than the defined length of the variable. SAS variables are fixed length so short values are padded with spaces.
Use the CALL SYMPUTX() when generating macro variables from a data step.
Use the TRIMMED keyword when generating macro variable from PROC SQL.
To set the name of the output file dynamically in a data step use the FILEVAR= option on the FILE statement. If you want comma delimited values use the DSD option. If you want to force quotes around values that don't need them then use the ~ modifier on the PUT statement.
So if your &BENPK and &COMP macro variables are just the values of the BENPK and COMP dataset variables then your code can be like this.
data _null_;
set &outdat.;
length filename $256 ;
filename=cats("&drv2./test/Current/",benpk,'_',comp,'_00.txt');
file out filevar=filename dsd mod;
put (name fname zip) (~) ;
run;
If they aren't dataset variables the instead of BENPK and COMP in the list of values for CATS() to concatenate then use "&BENPK" and "&COMP". Or use SYMGET('BENPK') and SYMGET('COMP').
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
i have used the below code to rename the external file.
data _null_;
RC1=rename("&drv2./test/Current/C.txt", "&drv2./test/Current/C.txt", "file");
run;