sas - PROC FREQ on multiple variables combined into one table -


i have following problem. need run proc freq on multiple variables, want output on same table. currently, proc freq statement tables erstatus age race, insurancestatus; calculate frequencies each variable , print them on separate tables. want data on 1 table.

any appreciated. thanks!

p.s. tried using proc tabulate, didn't not calculate n correctly, i'm not sure did wrong. here code proc tabulate. variables categorical, need know n , percentages.

proc tabulate data = bcanalysis; class erstatus prstatus race tumorstage insurancestatus; table (erstatus prstatus race tumorstage) * (n colpctn), insurancestatus; run; 

the above code not return correct frequencies based on insurancestatus 0 = insured , 1 = uninsured, proc freq does. doesn't calculate correctly rowpctn. way can proc freq calculate multiple variables on 1 table, or proc tabulate return correct frequencies, appreciated.

here nice image of output in simplified analysis of erstatus , insurancestatus. can see proc freq returns 204 people erstatus of 1 , insurancestatus of 1. that's correct. values in proc tabulate not. output

i'll answer separately answering other possible interpretation of question; when it's clarified i'll delete 1 or other.

if want in single printed table, either need use proc tabulate or need normalize data - meaning put in form of variable | value. proc freq not capable of doing multiple one-way frequencies in single table.

for proc tabulate, issue missing data. variable on class statement checked missingness, , if rows missing data of class variables, rows entirely excluded tabulation all variables.

you can override adding missing option on class statement, or in table statement, or in proc tabulate statement. so:

proc tabulate data = bcanalysis; class erstatus prstatus race tumorstage insurancestatus/missing; table (erstatus prstatus race tumorstage) * (n colpctn), insurancestatus; run; 

this result in different appearance on table, though, include missing rows in places do not want them, , they'll factored against colpctn when again don't want them.

typically manipulation necessary; easiest normalize data , run tabulation (using proc tabulate or proc freq, whichever more appropriate; tabulate has better percentaging options though) against normalized dataset.

let's have this:

data class;   set sashelp.class;    if _n_=5 call missing(age);   if _n_=3 call missing(sex); run; 

and want these 2 tables in 1 table.

proc freq data=class;   tables age sex; run; 

if this:

proc tabulate data=class;   class age sex;   tables (age sex),(n colpctn); run; 

then n=17 total both subtables - that's not want, want n=18. can do:

proc tabulate data=class;   class age sex/missing;   tables (age sex),(n colpctn); run; 

but that's not quite right either; want f have 8/18 = 44.44% , m 10/18 = 55.55%, not 42% , 53% 5% allocated missing row.

the way normalize data. means dataset 2 variables, varname , val, or whatever makes sense data, plus whatever identifier/demographic/whatnot variables might have. val has character unless of values numeric.

so example here normalize class age , sex variables. don't keep identifiers, in data, imagine insurancestatus kept there if understand you're doing in table. once have normalized table, use 2 variables, , construct denominator definition in proc tabulate have right basis pctn value. it's not quite same single table before - variable name in own column, not on top of list of values - looks better in opinion.

data class_norm;   set class;   length val $2;   varname='age';   val=put(age,2. -l);   if not missing(age) output;   varname='sex';   val=sex;   if not missing(sex) output;   keep varname val; run;   proc tabulate data=class_norm;   class varname val;   tables varname=' '*val=' ',n pctn<val>; run; 

if want better this, you'll have construct in proc report. gives flexibility, onerous program in also.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -