Help using Base SAS procedures

Aligning data by decimal point in a column

Reply
Occasional Contributor
Posts: 10

Aligning data by decimal point in a column

Hi,

 

I am creating a demographic summary with almost 50 segments. Some of the categorical variables have percentage next to it.

For some of the variables, only need to display proc means results.

1: Is there any way to right allign the proc mean result by a decimal point and put it in a character column?

2: I am using picture format to adjust the percentage for the few segments and its working fine but again number before the percentage is not right alligned, how can I fix it.

 

Thanks,

 

 

 

 

 

Super User
Super User
Posts: 9,599

Re: Aligning data by decimal point in a column

There are ways to align decimals (style align=decimal for one).  However if you want to see percentages - and in table outputs its normally count with percentage in brackets, it is far simpler to create a string variable output:

data want;
  set means_output;
  result1=cat(strip(put(n,best.)," (",strip(put(percent,6.2)),"%)");
run;

Then print the string value.  In this way you can combine values, add strings, and output in many ways without complex formats or tricks.

Occasional Contributor
Posts: 10

Re: Aligning data by decimal point in a column

Hi,
 Thanks for the reply.
The segment, which has proc mean result is different from the categorical segments.
Would it be possible to acheive (style align=decimal for one) in a datastep for the proc mean segments?
The below is just concatinating without allignment, I would like t oeven allign all segments and percentage value in the bracket.
result1=cat(strip(put(n,best.)," (",strip(put(percent,6.2)),"%)");
When i use the below picture format for values inside the brackets, its giving the desired result.
 
 

 picture percent      (round)

               0              ='(    0.0)'         (noedit)
              -1 <- < 0     ='   0.9)'  (prefix='(    ')
              0 <- < 10    ='   9.9)'  (prefix='(    ')
            10  - < 100   =' 99.9)'  (prefix='(  ')
                     100  = '(100)'        (noedit)

      ;

 
I would like to have reslut like below.
Seg1
      N             409
      Nmiss      100
      Mean         76.1
      SD             30.56
Seg2
 
      cat1             1 (    0.2)
      cat2             7 (    1.2)
      cat3           79 (  39.5)
      cat5         213 (  57.9)
 
Thanks,
 
 
Super User
Posts: 10,778

Re: Aligning data by decimal point in a column

If your ODS destination is RTF or PDF, Try:

 

style={just=dec}

Occasional Contributor
Posts: 10

Re: Aligning data by decimal point in a column

Thats was the first thing I tired, but it didn't work.

Wondering if there is any format to change the character (number) variable so it looks exactly like numeric value (Left alligned) apart from decimal number, as they need to be alliged by decimal points?

Super User
Posts: 13,542

Re: Aligning data by decimal point in a column


@hira wrote:

Thats was the first thing I tired, but it didn't work.

Wondering if there is any format to change the character (number) variable so it looks exactly like numeric value (Left alligned) apart from decimal number, as they need to be alliged by decimal points?


 

Aligning text is always dependent on font. An alignment built for Courier will not match when displayed using Times New Roman (or any proportional font in general). If you do not have complete control of the font all the way through all of the processes, reports and displays intended then the work is wasted. Or you get to repeat any solution that might work at every step where the font changes.

 

Personally I suspect that extracting the numeric portion, assuming there is a numeric portion as otherwise "decimal" would be the incorrect term, so that could be aligned and play around with displays of the non-numeric.

 

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Ask a Question
Discussion stats
  • 5 replies
  • 137 views
  • 0 likes
  • 4 in conversation