Help using Base SAS procedures

ODS PDF listing: table column values center alignment in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

ODS PDF listing: table column values center alignment in SAS

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;


Accepted Solutions
Solution
‎10-05-2011 09:14 AM
Super User
Super User
Posts: 7,076

Re: ODS PDF listing: table column values center alignment in SAS

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;

View solution in original post


All Replies
Regular Contributor
Regular Contributor
Posts: 166

ODS PDF listing: table column values center alignment in SAS

Hi,

Does this not work for you?

proc print data = sashelp.class style(column)=[just=center];

run;


Contributor
Posts: 55

ODS PDF listing: table column values center alignment in SAS

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.

Regular Contributor
Regular Contributor
Posts: 166

ODS PDF listing: table column values center alignment in SAS

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

Contributor
Posts: 55

ODS PDF listing: table column values center alignment in SAS

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.

Contributor
Posts: 66

Re: ODS PDF listing: table column values center alignment in SAS

Dear nishant nair, your reply is interesting for me Smiley Happy,

but how to generalize it to all tables in SAS outputs

from different PROCs ?

Thanks.

Super User
Super User
Posts: 7,076

Re: ODS PDF listing: table column values center alignment in SAS

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;

Contributor
Posts: 55

Re: ODS PDF listing: table column values center alignment in SAS

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.

Solution
‎10-05-2011 09:14 AM
Super User
Super User
Posts: 7,076

Re: ODS PDF listing: table column values center alignment in SAS

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;

Contributor
Posts: 55

ODS PDF listing: table column values center alignment in SAS

Thanks a lot for your code Tom. Now it meets my requirementSmiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 4031 views
  • 1 like
  • 4 in conversation