This code is the last part of my macro:
proc export data = allperiods
outfile = "g/entitysheets/test&entityname..csv"
dbms = csv replace;
run;
The data is exported correctly, except I'd like the name to be (for example) testEntityX.csv. But what I'm getting is testEntityX .csv. How can I get rid of those spaces without going through and deleting them manually?
Thanks for the help!
If spaces at the end of your macro variable are really the problem, you could progbably use it like:
g:\entitysheets\%sysfunc(strip(&entityname.)).csv
Art
How about if you use the strip or right function to get rid of the extra spaces? Of course, dependent on your code, you may have to wrap the function in a %sysfunc().
Art
I was looking into the strip function, but wasn't sure how I would use it on the file name (I'm new to SAS). Would I just say outfile = strip("g/entitysheets/test&entityname..csv")?
If spaces at the end of your macro variable are really the problem, you could progbably use it like:
g:\entitysheets\%sysfunc(strip(&entityname.)).csv
Art
Not too different that Art's suggestion, but there's also the %trim() macro function:
data _null_;
format var $20.;
var = 'file_20110708';
call symput('var',var);
run;
%put &var.;
%put filename is "c:\&var..csv";
%put filename is "c:\%trim(&var.).csv";
You can add %let entityname = &entityname; right before proc export and all the blanks are gone.
Thanks for all the help!
Everyone has suggested ways to FIX the problem after the fact. You may want to reflect on how the value was created and address the issue there. I suspect you created the value with CALL SYMPUT. SYMPUT does not trim the value of its arguments. You could use STRIP or TRIM with SYMPUT or use SYMPUTX a new version of SYMPUT that does STRIP the value of its arguments. SYMPUTX also quietly converts numeric to character, and has a third parameter for SCOPE.
data _null_;
call symputX('nx',_n_);
call symput('n',_n_);
run;
%put NOTE: **&N** **&nx**;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.