BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bballvas
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

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

bballvas
Calcite | Level 5

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")?

art297
Opal | Level 21

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

DF
Fluorite | Level 6 DF
Fluorite | Level 6

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";

andreas_lds
Jade | Level 19

You can add %let entityname = &entityname; right before proc export and all the blanks are gone.

bballvas
Calcite | Level 5

Thanks for all the help!

data_null__
Jade | Level 19

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**;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 963 views
  • 7 likes
  • 5 in conversation