Help using Base SAS procedures

proc tabulate percentage

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

proc tabulate percentage

Hi Experts,

I have a question on proc tabulate.the data look like

data test;

do grp=1 to 6;

  do flg='Yes','No';

   do sec='dsfsa', 'fdafa', 'afafa';

   output;

  end;

end;

end;

run;

proc tabulate data=test;

class grp flg sec;

table grp *FLG ,sec='section'

  * (n='n' * f=10. COLPCTN='%' * f=7.2 )/ misstext='0' rts=40;

run;

my o/p:

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†

‚                                      ‚                        section                         ‚

‚                                      ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰

‚                                      ‚      afafa       ‚      dsfsa       ‚      fdafa       ‚

‚                                      ‡ƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒ‰

‚                                      ‚    n     ‚   %   ‚    n     ‚   %   ‚    n     ‚   %   ‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚grp               ‚flg                ‚          ‚       ‚          ‚       ‚          ‚       ‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰          ‚       ‚          ‚       ‚          ‚       ‚

‚1                 ‚No                 ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚2                 ‚No                 ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚3                 ‚No                 ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚4                 ‚No                 ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   8.33‚         1‚   8.33‚         1‚   8.33‚

Šƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒŒ

but my desired o/p is

„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†

‚                                      ‚                        section                         ‚

‚                                      ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰

‚                                      ‚      afafa       ‚      dsfsa       ‚      fdafa       ‚

‚                                      ‡ƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒ‰

‚                                      ‚    n     ‚   %   ‚    n     ‚   %   ‚    n     ‚   %   ‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚grp               ‚flg                ‚          ‚       ‚          ‚       ‚          ‚       ‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰          ‚       ‚          ‚       ‚          ‚       ‚

‚1                 ‚No                 ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚2                 ‚No                 ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚3                 ‚No                 ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚4                 ‚No                 ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

‚                  ‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒ‰

‚                  ‚Yes                ‚         1‚   50.00‚         1‚   50.00‚         1‚   50.00‚

Šƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒŒ

can i produce this kid of output by using proc report?

Thanks

Sam


Accepted Solutions
Solution
‎08-13-2013 02:14 PM
Super Contributor
Posts: 543

Re: proc tabulate percentage

Hi.

Your code is very close to accomplist what you wanted:

proc tabulate data=test;

class grp flg sec;

table grp *FLG ,sec='section'

  * (n='n' * f=10. pctn<flg>='%' * f=7.2 )/ misstext='0' rts=40;

run;

Good luck!

Anca.

View solution in original post


All Replies
Solution
‎08-13-2013 02:14 PM
Super Contributor
Posts: 543

Re: proc tabulate percentage

Hi.

Your code is very close to accomplist what you wanted:

proc tabulate data=test;

class grp flg sec;

table grp *FLG ,sec='section'

  * (n='n' * f=10. pctn<flg>='%' * f=7.2 )/ misstext='0' rts=40;

run;

Good luck!

Anca.

Regular Contributor
Posts: 168

Re: proc tabulate percentage

Posted in reply to AncaTilea


Hi Anca,

Thank you !!! I Tried  PCTN but i used wrong variable , i am applying on grp!!!! . Now i  got what i want.

Is the same table can we generate using proc report. because i need to add another variable like sec(afafa,dsfsa ‚fdafa) , that varible name is mflag(Yes,NO). i am unable to do it in one table by using proc tabluate,

my final o/p with new added variable is shown like this

                                                                            section                                                        mflag

grp                  flg                               afafa              dsfsa           fdafa                                  Yes                   No

                                                        n         %          n        %       n         %                         n         %          n        %        

1                    No                            XX        XX        XX       XX       XX      XX                       XX        XX         XX       XX

                      Yes                          XX        XX        XX       XX       XX      XX                       XX        XX         XX       XX

I below is the code i am using but it throws a error in log:

proc tabulate data=subgrps;

class grp flg sec mflag;

table grp *flg ,sec=’Section’

* (n='n' * f=10. PCTN<FLG>='%' * f=7.2 ), mflag=’Mflag’

* (n='n' * f=10. PCTN<FLG>='%' * f=7.2 )/ misstext='0' rts=40;

run;

Thanks

Sam

Super Contributor
Posts: 543

Re: proc tabulate percentage

Hi. glad it worked.

You need to remove the comma before the mflag = "Mflag" * (....);

Using this data:

data test;

do grp=1 to 4;

  do flg='Yes','No';

   do mflag  = "Yes", "No";

   do sec='dsfsa', 'fdafa', 'afafa';

   output;

  end;

  end;

end;

end;

run;

proc tabulate data=test;

class grp flg sec mflag;

table grp *flg ,

  sec="Section" * (n="n" * f=10. PCTN<FLG>="%" * f=7.2 )

  mflag="Mflag" * (n="n" * f=10. PCTN<FLG>="%" * f=7.2 )

  / misstext="0" rts=40;

run;

Good luck.

Anca.

Regular Contributor
Posts: 168

Re: proc tabulate percentage

Posted in reply to AncaTilea

Thank you so much  Anca. It worked!!!!! That is what exactly i want.

Regards

Sam.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 191 views
  • 2 likes
  • 2 in conversation