BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasheadache
Obsidian | Level 7

I need some further assistance on a solution detailed in a previous post please.

 

Solved: Re: ODS Excel - problem with wrap text - SAS Support Communities

 

My issue is after passing the list of length values to the macro variable, when it then applies this in the proc print via the 'absolute_column_width = "&length_var"' section  it's applying the first length from the macro variable to all columns, rather than being dynamic and changing for each one. 

 

 

 

/* creating a macro variable containing these lengths separated by a comma */
proc sql noprint ; 
select length into : length_var separated by ',' 
from other_name ; 
quit ;

/* EXPORT */

ods excel file="path\name_output.xlsx" 
options(
flow = "header, data" 
absolute_column_width = "&length_var" 
absolute_row_height = "20px"
);

 

 

Note: I am not using 'tagsets.excel' as we only have 'tagsets.excelbase' or 'tagsets.excelxp' in our current sas installation, but I don't think this is the issue anyway. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I am not able to reproduce this.

 

%let length_var=8,11,14,125,8,8,8,8,8,11,125,14,14,14;
ods excel file="test.xlsx" options(flow = "header, data" absolute_column_width="&length_var" absolute_row_height = "20px");
proc print data=sashelp.cars noobs;
run;
ods excel close;

PaigeMiller_0-1701950776166.png

 

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

What is the value of the macro variable &length_var ?

 

Can you show us the entire code instead of fragments?

 

You mention tagsets.excelxp but you are not using tagsets.excelxp, why? You are using ODS EXCEL, not tagsets.excelcp

--
Paige Miller
sasheadache
Obsidian | Level 7

The full code extract was on the original post - included now for reference. 

In my adapted version of this code the only difference is the fact I am using 'ods tagsets.excelbase' instead of 'ods excel' from the original post.

 

/* 1) proc contents to recover the length of each variables */
proc contents data = table_you_want_export 
out = other_name (keep = varnum length) noprint ; 
run ;

/* sorting by varnum to have the same order that the table you want export */
proc sort data = other_name ; 
by varnum ; 
run ;
	
/* creating a macro variable containing these lengths separated by a comma */
proc sql noprint ; 
select length into : length_var separated by ',' 
from other_name ; 
quit ;

/* EXPORT */

ods excel file="path\name_output.xlsx" 
options(
flow = "header, data" 
absolute_column_width = "&length_var" 
absolute_row_height = "20px"
); 

Proc print data = table_you_want_export noobs ;
run ;

ods excel close ;

The value of the macro variable resolves to: 

83 %put &length_var.;
SYMBOLGEN: Macro variable LENGTH_VAR resolves to 8,11,14,125,8,8,8,8,8,11,125,14,14,14
8,11,14,125,8,8,8,8,8,11,125,14,14,14

The first value in the macro variable is 8 and the proc print is then applying this length to all columns.

 

Thanks

 

 

 

 

PaigeMiller
Diamond | Level 26

I am not able to reproduce this.

 

%let length_var=8,11,14,125,8,8,8,8,8,11,125,14,14,14;
ods excel file="test.xlsx" options(flow = "header, data" absolute_column_width="&length_var" absolute_row_height = "20px");
proc print data=sashelp.cars noobs;
run;
ods excel close;

PaigeMiller_0-1701950776166.png

 

--
Paige Miller
sasheadache
Obsidian | Level 7

So I don't have the ability to simply use 'ods excel' because it produces excel files which are full of nonsense i.e. special characters & symbols (guessing its a SAS config issue at my company). But the good news is I have now managed to replace the same steps using my current method of output using 'ods tagsets.excelbase'. 

 

I didn't realise until now how many different variations there were with outputting and formatting data to Excel, so that should keep me busy upskilling for a few weeks. 🙂

 

Thanks for taking the time to reply - all the best!

ballardw
Super User

And the values of Length in data set OTHER_NAME are what?

 

You should be made aware that PX is not a portable unit of measure. Using such a unit becomes dependent on the display and running the code on a different system can result on unreadable text.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1107 views
  • 0 likes
  • 3 in conversation