Hi,
In the pdf output I want the table column all values center aligned, how do I achieve this? Currently alignment is for character it is left justified and numbers right justified. I want all the values to be center aligned. Please help.
ods pdf close;
ods listing;
ods pdf close;
ods listing close;
ods results off;
options papersize=A4 nodate;
options orientation=landscape leftmargin="0.2cm" rightmargin="0.2cm" topmargin="0.5cm" bottommargin="0.5cm";
goptions ftext = "helvetica/bold" noborder device=CGMOF97P NOGRAPHRC;
ods pdf style=statdoc file='temp.pdf'
notoc style=statdoc;
proc print data = sashelp.class;
run;
ods pdf close;
ods results on;
ods listing;
Do you care about the order of the variables?
If not then use
var _numeric_ / style=[just=center];
var _character_ ;
Otherwise you might want to use code generation from the metadata. Here is an example using PROC SQL to generate the statements into a macro varable.
data mydata ; set sashelp.class; run;
proc sql noprint ;
select catx(' ','var',name,style) , varnum
into :varlist separated by ';' , :dummy
from ( select name,varnum
,case when (type='num') then '/ style=[just=center]'
else ' ' end as style
from dictionary.columns
where libname='WORK' and memname='MYDATA'
)
order by varnum
;
quit;
proc print data=work.mydata noobs;
&varlist;
run;
Hi,
Does this not work for you?
proc print data = sashelp.class style(column)=[just=center];
run;
Hi,
Thanks a lot for your code. Its working but now my requirement has slightly changed. How to align only the number values centered from the tables? If it is character then it should be default alignment.
Hi,
In proc print you can define the alignment for indivdual columns using the VAR and STYLE statements
for example
proc print data=sashelp.class noobs;
var name sex;
var age / style=[just=center];
run;
Click here for one of the Papers That could prove useful
Thanks for the code. Sure this code will work when variables are fixed. Actually, in real time what happens is variables will be dynamic then I am not sure how to do.
For Example: Employee table contains Name, Age, Sex, Salary, Bonus.
Here Name, age, sex, salary variables are fixed. Bonus variable is dynamic that is if employee has got any bonus then only Bonus variable will appear.
Some times data will be available in this format Name, age, sex, salary
Some times data will be available in this format Name, age, sex, salary, bonus
So in this case how to center align only age, salary, bonus variables as these three variables are numeric. Please help.
Thanks in Advance.
Dear nishant nair, your reply is interesting for me ,
but how to generalize it to all tables in SAS outputs
from different PROCs ?
Thanks.
You can move the style option to the PROC PRINT statement.
proc print data=sashelp.class noobs
style(header)=[just=center]
style(data)=[just=center]
;
run;
You can also change the VAR statement to include all of the variables.
proc print data=sashelp.class noobs;
var _all_ / style=[just=center];
run;
Thanks Tom but this code will center align all the variables and it will not meet my requirement where in only numeric variables that is age, salary, bonus should be center aligned and that too bonus variable is dynamic.
Do you care about the order of the variables?
If not then use
var _numeric_ / style=[just=center];
var _character_ ;
Otherwise you might want to use code generation from the metadata. Here is an example using PROC SQL to generate the statements into a macro varable.
data mydata ; set sashelp.class; run;
proc sql noprint ;
select catx(' ','var',name,style) , varnum
into :varlist separated by ';' , :dummy
from ( select name,varnum
,case when (type='num') then '/ style=[just=center]'
else ' ' end as style
from dictionary.columns
where libname='WORK' and memname='MYDATA'
)
order by varnum
;
quit;
proc print data=work.mydata noobs;
&varlist;
run;
Thanks a lot for your code Tom. Now it meets my requirement
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.