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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

9 REPLIES 9
NN
Quartz | Level 8 NN
Quartz | Level 8

Hi,

Does this not work for you?

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

run;


1239
Calcite | Level 5

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.

NN
Quartz | Level 8 NN
Quartz | Level 8

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

1239
Calcite | Level 5

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.

stan
Quartz | Level 8

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.

Tom
Super User Tom
Super User

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;

1239
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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;

1239
Calcite | Level 5

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

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!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 6990 views
  • 1 like
  • 4 in conversation