BookmarkSubscribeRSS Feed
hira
Calcite | Level 5

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,

 

 

 

 

 

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

hira
Calcite | Level 5
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,
 
 
Ksharp
Super User

If your ODS destination is RTF or PDF, Try:

 

style={just=dec}

hira
Calcite | Level 5

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?

ballardw
Super User

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 6024 views
  • 0 likes
  • 4 in conversation