DATA Step, Macro, Functions and more

Left or right align alpha variable values in a column

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

Left or right align alpha variable values in a column

Hi

I am looking around for a way to left or right align alpha variable values in a data set. I really found anything that would seem to work yet. Is there a way to do this?

Paul


Accepted Solutions
Solution
‎05-19-2013 12:50 PM
SAS Super FREQ
Posts: 8,739

Re: Left or right align alpha variable values in a column

Hi:

  You can left or right align variables when you display them on a REPORT, but SAS does not store anything about "justification" or "alignment" in the descriptor portion of the SAS DATASET. The information that does get stored is information like: variable length, variable label, variable informat, variable format and this information could be used by a procedure at report time to display the variable values. For example, the number 12345, might be displayed different ways, depending on whether the stored format was comma8. or comma8.3 or dollar10.2. However, there is nothing about alignment that would be useful when storing a number on disk. Text alignment or number alignment on a report really depends on whether the report format supports control of text alignment -- generally speaking, you can influence alignment in ODS destinations better than in the LISTING destination (or Output Window).

  Typically, for reports, numeric variables are right-aligned or right-justified and character variables are left-aligned or left-justified, but, depending on your procedure and your destination of choice (LISTING vs HTML, RTF, PDF), you can have an impact on the alignment of a variable header and values at report time. See the program below using PROC PRINT. There would be slightly different syntax for PROC REPORT and PROC TABULATE.

cynthia

ods html file='c:\temp\change_just.html';
ods rtf file='c:\temp\change_just.rtf';
ods pdf file='c:\temp\change_just.pdf';
ods csv file='c:\temp\csv_just.csv';

  

proc print data=sashelp.class noobs
  style(header)={just=c};
  var name / style(data)={just=r width=1.5in};
  var age / style(data)={just=c width=1.0in};
  var height / style(data)={just=l width=.75in};
  var weight / style(data)={just=c width=.75in};
run;
ods _all_ close;

View solution in original post


All Replies
Solution
‎05-19-2013 12:50 PM
SAS Super FREQ
Posts: 8,739

Re: Left or right align alpha variable values in a column

Hi:

  You can left or right align variables when you display them on a REPORT, but SAS does not store anything about "justification" or "alignment" in the descriptor portion of the SAS DATASET. The information that does get stored is information like: variable length, variable label, variable informat, variable format and this information could be used by a procedure at report time to display the variable values. For example, the number 12345, might be displayed different ways, depending on whether the stored format was comma8. or comma8.3 or dollar10.2. However, there is nothing about alignment that would be useful when storing a number on disk. Text alignment or number alignment on a report really depends on whether the report format supports control of text alignment -- generally speaking, you can influence alignment in ODS destinations better than in the LISTING destination (or Output Window).

  Typically, for reports, numeric variables are right-aligned or right-justified and character variables are left-aligned or left-justified, but, depending on your procedure and your destination of choice (LISTING vs HTML, RTF, PDF), you can have an impact on the alignment of a variable header and values at report time. See the program below using PROC PRINT. There would be slightly different syntax for PROC REPORT and PROC TABULATE.

cynthia

ods html file='c:\temp\change_just.html';
ods rtf file='c:\temp\change_just.rtf';
ods pdf file='c:\temp\change_just.pdf';
ods csv file='c:\temp\csv_just.csv';

  

proc print data=sashelp.class noobs
  style(header)={just=c};
  var name / style(data)={just=r width=1.5in};
  var age / style(data)={just=c width=1.0in};
  var height / style(data)={just=l width=.75in};
  var weight / style(data)={just=c width=.75in};
run;
ods _all_ close;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 1400 views
  • 0 likes
  • 2 in conversation