BookmarkSubscribeRSS Feed
sasban
Obsidian | Level 7

I need to create a demographic summary table. Since I'm doing this for the first time, I'm looking for the reference that describes creating table with continuous and categorical variables explicitly (possibly with step by step coding). Any suggestions please? 

9 REPLIES 9
Reeza
Super User

Search LexJansen.com

 

And note that everyone defines demographic table differently, so you may need to customize things as needed.

It seems down right now, but should be up soon. 

 

Or search on here, there's a lot of examples. John King has some great papers on this as well. 

 

ballardw
Super User

My first suggestion is to make sure your data is as clean as possible. Each field involved should have an agreed upon content and be in that form. For instance if Gender or Sex is a field is it allowed to be missing or something like "don't know" or "refused". If the values are supposed to be "Male" or "Female" then beware of case ( "male" "female"), abbreviations ("M" "F" or "m" "f").

 

Second is if you have continuous values like Age but want to report age groups to investigate custom formats so you can make changes without having to add multiple variables to your data for that purpose.

 

And if you are reporting percentages make sure everyone involved knows what the denominator(s) involved should be: All records or records with valid values.

 

Very likely questions will arise if the total counts for all Sexes, for example, don't match total counts for all ages.

sasban
Obsidian | Level 7

@ballardw- My data is clean already. My problem here is the proper use of proc freq, proc transpose... things are required in proper order.

 

 

mkeintz
PROC Star

Could you provide a template of what your demographic table should look like?

 

I presume it will be a table of frequencies cross-classified by demographic variables  If so, which vars?   SEX,RACE,AGE_GROUP..... other vars like IMMIGRANT/NATIVEBORN, Education level?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sasban
Obsidian | Level 7

@mkeintz,

 

Yes, It is like this:  

                                                Treatment A                        Treatment B                          Total

                  Sex                 

                   M                         50 (10%)                               100 (20%)                         500 (100%)

                   F

                   Race

                   White

                   Asian

                  .

                  .

mkeintz
PROC Star

You can get close to this with a PROC TABULATE.

 

Assume you have a data set of individuals with variables SEX ("M" or "F"), Race ("White", "Asian").

 

Then you can

proc tabulate data=have noseps;
  class age sex treatment;
  tables age sex all, (treatment all)*(N pctn) / rts=10;
run;

 

which gives the layout you want, but is ugly.  You can improve the appearance:

 

proc format ;
  picture mypct  low-high='00.0%';
run;
proc tabulate data=have noseps;
  class age sex treatment;
  tables age sex all, (treatment all)*(N=''*f=comma4.0 pctn=''*f=mypct5.1) / rts=10;
run;

 

And if you want better than that, I think you need to learn about PROC REPORT.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sasban
Obsidian | Level 7

@mkeintz, I did following and did proc report with other variables. But could not calculate total.

 

Proc import datafile="/folders/myshortcuts/Myfolders/SAS Exercise/DM_Exercise1.xls"
    Out=Q1
    Dbms=XLS replace;
run;
 
 
proc sort data=Q1 nodupkey;
by usubjid;
run;
 
 
data Q1a;
set Q1 (keep=agegr1 sex age race ethnic trt01pn pltcnt);
run;
 
 
proc freq data=Q1a noprint;
tables trt01pn*agegr1/missing outpct out=Q1afreq_agegr1;
run;
 
data Q1afreqper_agegr1;
set Q1afreq_agegr1;
length value $25;
value=put(count, 4.)!!' ('!!put(pct_row,4.1)!!'%)';
run;
 
proc sort data=Q1afreqper_agegr1;
by agegr1;
run;
 
proc transpose data=Q1afreqper_agegr1 out=Q1atrans_agegr1;
by agegr1;
var value;
ID trt01pn;
run;
 
data labelagegr1;
label="Age Categorization (%)";
run;
 
data agegr1label;
length label $25;
set labelagegr1 Q1atrans_agegr1;
keep label _0 _1 _2; 
if _n_>1 then select;
when (agegr1='<65') label="<65";
when (agegr1='>=65') label=">=65";
otherwise;
end;
run;
 

 

 

dimrana
Calcite | Level 5

 Did you find the solution? Can u share the solution on how to create demographic table?

Cynthia_sas
SAS Super FREQ

Hi:

   I show one approach to create several tables/reports (for RTF output) in my paper, Creating Complex Reports http://www2.sas.com/proceedings/forum2008/173-2008.pdf (page 9)demog.png.

 

  TABULATE is another approach, but TABULATE does not give you as much control over break lines and spacing.

 

  You'll find the programs that accompany the paper here: http://support.sas.com/rnd/papers/#RegUsers_2008 scroll down on the page for 2008 and look for the paper title.

 

This is just one idea. I second the idea of searching on www.lexjansen.com because the PharmaSUG and PhUSE presenters have talked a lot about producing these types of reports.

 

Cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 8944 views
  • 4 likes
  • 6 in conversation