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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

1 REPLY 1
Cynthia_sas
SAS Super FREQ

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;

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!

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.

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
  • 1 reply
  • 9302 views
  • 0 likes
  • 2 in conversation