<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: A question of creating demographic table in the sas? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910231#M358989</link>
    <description>&lt;P&gt;yeah but you have the follow the table shell and this is very common. statisticians design the shells.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2024 13:09:48 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2024-01-03T13:09:48Z</dc:date>
    <item>
      <title>A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910038#M358917</link>
      <description>&lt;P&gt;Hi guys! I'm creating a demographic table and having a question in the categorical variable.&lt;/P&gt;&lt;P&gt;So for the categorical variable AGegr1, I want to create a table like below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-02 at 3.42.47 AM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92152iC67DE3E492784EBC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-01-02 at 3.42.47 AM.png" alt="Screenshot 2024-01-02 at 3.42.47 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have utilized the proc freq function to create it, and it is easy to get the last 3 rows while i find it is hard to get the first row;&lt;/P&gt;&lt;P&gt;here is my code:&lt;/P&gt;&lt;P&gt;proc freq data=ADSL noprint;&lt;BR /&gt;tables Trt01an *AGegr1 / missing outpct out=AGegr1;&lt;BR /&gt;tables Trt01an/ missing out=AGegr1_n(drop=percent rename=(count=total));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data AGegr1;&lt;BR /&gt;merge AGegr1(in=a) AGegr1_n(in=b);&lt;BR /&gt;by trt01an;&lt;BR /&gt;if a and b;&lt;BR /&gt;length value$11.;&lt;BR /&gt;value=put(count,3.)|| "(" || put(pct_row,4.1)||"%)";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=AGegr1;&lt;BR /&gt;by AGegr1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=AGegr1&lt;BR /&gt;out=AGegr1 (drop=_name_)&lt;BR /&gt;prefix=Trt;&lt;BR /&gt;by AGegr1;&lt;BR /&gt;var value;&lt;BR /&gt;id Trt01an;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and my output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-02 at 3.51.02 AM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92153i7A52FCACF6D6359A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-01-02 at 3.51.02 AM.png" alt="Screenshot 2024-01-02 at 3.51.02 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;there's still no first row, thanks for ur help!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 08:51:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910038#M358917</guid>
      <dc:creator>Sikcion</dc:creator>
      <dc:date>2024-01-02T08:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910044#M358921</link>
      <description>&lt;P&gt;Please supply an example of your initial dataset, in a DATA step with DATALINES.&amp;nbsp;&lt;STRONG&gt;Do not skip this.&lt;/STRONG&gt; If custom formats are used, do also include the PROC FORMAT code.&lt;/P&gt;
&lt;P&gt;Use the "little running man" button to post the code.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 10:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910044#M358921</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-02T10:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910054#M358926</link>
      <description>&lt;P&gt;If you have some flexibility with the layout (which normally makes things much easier) then a simple Proc Tabulate could do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value ageGroup
  low-12 = '&amp;lt;=12'
  12-14  = '&amp;gt;12 to 14'
  14-high= '&amp;gt;14'
  ;
run;

proc tabulate data=sashelp.class;
  class age sex;
  format age ageGroup.;
  table age all='Total', 
        (sex=' ' all='Total')*(n='Count' pctn='%'*f=5.1)
  ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1704196626339.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92158i7F0E690CB8DE88F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1704196626339.png" alt="Patrick_0-1704196626339.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you need to stick to your layout then eventually Proc Report with some Break After logic could do it. Not sure - I don't have enough experience with this Proc to be sure so just an idea worth investigating.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 12:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910054#M358926</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-02T12:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910062#M358929</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446290"&gt;@Sikcion&lt;/a&gt;&amp;nbsp;I strongly endorse the table layout from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;as something that is easy to produce, and in my opinion is just as readable as something that displays N and percent as a text string thusly: 3 (9.1%). Instead, the N and percent each have its own column, but everyone understand this and all the information is there, you lose nothing by adopting the table layout shown by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it has to be in the format you showed in your original post, then please look at the &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030" target="_self"&gt;%TABLEN macro&lt;/A&gt;, which will do this for you.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 12:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910062#M358929</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-02T12:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910090#M358948</link>
      <description>&lt;P&gt;did you output 2 datasets from proc freq? it looks like those should be combined vertically, not horizontally.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jan 2024 15:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910090#M358948</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-02T15:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910101#M358949</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tarheel13_0-1704212591194.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92169i4D26123C2470D1E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tarheel13_0-1704212591194.png" alt="tarheel13_0-1704212591194.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You can try this code but use your data.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value agefmt
   18 - 40= '18 - 40'
   41 - 64 = '41 - 64' 
   65 - HIGH = '&amp;gt;= 65'
   ;
   value trtf
   1='Active'
   2='Placebo'
   ;
run;

proc sql noprint;
   select count(distinct usubjid) into: n1
      from echo.dm
      where armcd='ECHOMAX';
   select count(distinct usubjid) into: n2
      from echo.dm
      where armcd='PLACEBO';
quit;
%put &amp;amp;=n1 &amp;amp;=n2;

proc means data = dm completetypes n noprint nway;
   format age agefmt. trt01an trtf.;
   class trt01an age / preloadfmt;
   var age;
   output out=agestats n=_n;
run;

proc sort data=agestats;
   by age;
run;

proc transpose data = agestats out=agestats_t prefix=col;
   by age;
   var _n;
run;

proc means data = dm completetypes n noprint nway; 
   format trt01an trtf.;
   class trt01an / preloadfmt;
   var trt01an;
   output out=trtcounts n=_n;
run;

proc sort data=trtcounts;
   by trt01an;
run;

proc transpose data = trtcounts out=trtcounts_t prefix=col;
   var _n;
run;

data stack;
   length cat0 $200;
   set trtcounts_t(in=a) agestats_t(in=b);
   if a then cat0='n';
   else cat0 = put(age,agefmt.);
   array trtcounts[2] (&amp;amp;n1 &amp;amp;n2);
   array cnts[2] col1 col2;
   array pcts[2] pct1 pct2;
   array values[2] $14 value1-value2;
   if b then do;
      do i=1 to dim(cnts);
         if missing(cnts[i])=0 then pcts[i] = 100*cnts[i]/trtcounts[i];
         values[i]=strip(put(cnts[i],8.))||'('||strip(put(pcts[i],5.1))||')';
      end;
   end;
   if a then do;
      do i= 1 to dim(cnts);
       values[i] = strip(put(cnts[i],8.));
      end;
   end;
   drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jan 2024 16:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910101#M358949</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-02T16:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910181#M358971</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value ageGroup
  low-30 = '&amp;lt;=30'
  30&amp;lt;-60  = '&amp;gt;30 to 60'
  60&amp;lt;-high= '&amp;gt;60'
  ;
run;
data have;
 set sashelp.heart;
 _ageatstart=put(ageatstart,ageGroup. -l);
run;

proc sql;
create table want as
select 'n' as a length=80 label='Age group (yr)',bp_status,put(count(*),best. -l) as value length=80
 from have 
  where _ageatstart is not missing and bp_status is not missing
   group by bp_status
union all
select _ageatstart,bp_status,
cats(put(count(*),best. -l),'(',put(count(*)/(select count(*) from have where bp_status=a.bp_status),percent8.2),')')
 from have as a
  where _ageatstart is not missing and bp_status is not missing
   group by  _ageatstart,bp_status
;
quit;
proc report data=want nowd;
column a value,bp_status;
define a/group order=data;
define bp_status/across order=data descending;
define value/group '';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1704250743324.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92198iD49FFA7A55A1A630/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1704250743324.png" alt="Ksharp_0-1704250743324.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 02:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910181#M358971</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-03T02:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910218#M358983</link>
      <description>&lt;P&gt;I now present an opinion. Feel free to disagree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I talked about readability in my earlier post, it is my opinion that the table produced by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;is the most readable; then the table at the beginning of the original message is next most readable, because there is a space between the N and the parenthesis enclosing the percent; and the least readable is the table above from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;, the lack of having a space between the N and the parenthesis making it harder to read than the others (although clearly this is easily fixed).&amp;nbsp;If I was a professor grading the presentations that I have discussed, Patrick would get an A+, and the other table would get lower grades.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;People don't think about readability because they are so highly focused on getting the code to work. But readability of your table is very important as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But also, in terms of coding, the table by Patrick takes the least effort. So I prefer that one for a number of reasons.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 12:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910218#M358983</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-03T12:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910231#M358989</link>
      <description>&lt;P&gt;yeah but you have the follow the table shell and this is very common. statisticians design the shells.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 13:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910231#M358989</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-03T13:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910235#M358991</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;yeah but you have the follow the table shell and this is very common. statisticians design the shells.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am a statistician, and I have never felt that I have to follow the layout shown. In fact, to me, making something readable is more important than following the exact layout shown.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 13:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910235#M358991</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-03T13:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910237#M358992</link>
      <description>&lt;P&gt;but this is standard for pharmaceutical industry. programmers have to follow the shells.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 13:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910237#M358992</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-01-03T13:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: A question of creating demographic table in the sas?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910356#M359014</link>
      <description>Paige,&lt;BR /&gt;It is about stuff submitted to FDA ,not about " If I was a professor grading the presentations".&lt;BR /&gt;I agreed with tarheel . There are standard table layout you have to follow up if you are in Pharam field . It is not up to you to discuss these questions, it is question for  statisticians  and FDA .&lt;BR /&gt;You just followed it if you are a sas programmer .</description>
      <pubDate>Thu, 04 Jan 2024 01:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-of-creating-demographic-table-in-the-sas/m-p/910356#M359014</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-04T01:02:41Z</dc:date>
    </item>
  </channel>
</rss>

