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

Hi,

 

I'm just being lazy here but I'm trying to find a way to use &syslast in conjunction with a macro date variable (called dm_mrd_d) to name a data set that I am exporting to Excel in Base SAS 9.4. Initially when was doing this, I was finding 16 trailing blanks between the &syslast macro variable and the &dm_mrd_d macro variable.

 

Having done some investigation, I found out about the %qcmpres macro which I hoped would let me achieve what I was trying to. My code now reads: -

 

 

proc export data= &syslast

 

outfile= "\\appsl\users\rob\%qcmpres(&syslast._&dm_mrd_d.).xls"

dbms=excel replace;

run;

 

and the macros resolve to: -

 

WORK.WORK_PHONES_ONLY _20180316

 

I'd like to get rid of the last trailing blank so the file that is created has no blanks in the name but am not sure how. When I check the log with SYMBOLGEN on, I see the following: -

 

SYMBOLGEN: Macro variable I resolves to 22

 

This is the length of the filename plus one trailing blank so I think this is the point at which I need to remove that but just not sure how.

 

Hopefully I've posted enough information but if any more is needed, please let me know.

 

Thanks,

Rob

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Build the filename in a data step and use trim() to get rid of any trailing blanks:

data _null_;
outfile = trim("&syslast.") !! trim("_&dm_mrd_d.") !! '.xls');
call symputx('outfile',outfile);
run;

And use &outfile in the proc export statement.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Build the filename in a data step and use trim() to get rid of any trailing blanks:

data _null_;
outfile = trim("&syslast.") !! trim("_&dm_mrd_d.") !! '.xls');
call symputx('outfile',outfile);
run;

And use &outfile in the proc export statement.

robulon
Quartz | Level 8
Brilliant, thanks Kurt
Ksharp
Super User
outfile= "\\appsl\users\rob\%trim(&syslast.)%left(_&dm_mrd_d.).xls"
Tom
Super User Tom
Super User

The blanks on the end of SYSLAST are not macro quoted. So just assigning the value to another macro variable will remove them.

%let dsn=&syslast ;

proc export data= &dsn
  outfile= "\\appsl\users\rob\&dsn._&dm_mrd_d..xls"
  dbms=excel replace
;
run;

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
  • 5 replies
  • 803 views
  • 0 likes
  • 4 in conversation