SAS Demographic Table
I have been trying to create a demographic table like below this but I can't seem append the different tables. Please advise on where I can make adjustments in the code.
Group A Group B
chort 1 cohort 2 cohort 3 subtotal cohort 4 cohort 5 cohort 6 subtotal
Age
n
mean
sd
median
min
Gender
n
female
male
Race
n
white
asian
hispanic
black
My Code:
PROC FORMAT;
value content
1=' '
2='Age'
3='Gender'
4='Race'
value sex
1=' n'
2=' female'
3=' male';
value race
1=' n'
2=' white'
3=' asian'
4=' hispanic'
5=' black';
value stat
1=' n'
2=' Mean'
3=' Std. Dev.'
4=' Median'
5=' Minimum';
RUN;
DATA testtest;
SET test.test(keep = id group cohort age gender race);
RUN;
data tottest;
set testtest;
output;
if prxmatch('m/COHORT 1|COHORT 2|COHORT 3/oi', cohort) then do;
cohort='Subtotal';
output;
end;
if prxmatch('m/COHORT 4|COHORT 5|COHORT 6/oi', cohort) then do;
cohort='Subtotal';
output;
end;
run;
data count;
if 0 then set testtest nobs=npats;
call symput('npats',put(npats,1.));
stop;
run;
proc freq data=tottest;
tables cohort /out=patk0 noprint;
tables cohort*sex /out=sex0 noprint;
tables cohort*race /out=race0 noprint;
run;
PROC MEANS DATA = testtest n mean std min median;
class cohort;
VAR age;
RUN;
I know that I would have to transpose it and out it in a report. But before I do that, how do I get the variable out of my proc means, proc freq, etc?
sas tabular
|
show 3 more comments
I have been trying to create a demographic table like below this but I can't seem append the different tables. Please advise on where I can make adjustments in the code.
Group A Group B
chort 1 cohort 2 cohort 3 subtotal cohort 4 cohort 5 cohort 6 subtotal
Age
n
mean
sd
median
min
Gender
n
female
male
Race
n
white
asian
hispanic
black
My Code:
PROC FORMAT;
value content
1=' '
2='Age'
3='Gender'
4='Race'
value sex
1=' n'
2=' female'
3=' male';
value race
1=' n'
2=' white'
3=' asian'
4=' hispanic'
5=' black';
value stat
1=' n'
2=' Mean'
3=' Std. Dev.'
4=' Median'
5=' Minimum';
RUN;
DATA testtest;
SET test.test(keep = id group cohort age gender race);
RUN;
data tottest;
set testtest;
output;
if prxmatch('m/COHORT 1|COHORT 2|COHORT 3/oi', cohort) then do;
cohort='Subtotal';
output;
end;
if prxmatch('m/COHORT 4|COHORT 5|COHORT 6/oi', cohort) then do;
cohort='Subtotal';
output;
end;
run;
data count;
if 0 then set testtest nobs=npats;
call symput('npats',put(npats,1.));
stop;
run;
proc freq data=tottest;
tables cohort /out=patk0 noprint;
tables cohort*sex /out=sex0 noprint;
tables cohort*race /out=race0 noprint;
run;
PROC MEANS DATA = testtest n mean std min median;
class cohort;
VAR age;
RUN;
I know that I would have to transpose it and out it in a report. But before I do that, how do I get the variable out of my proc means, proc freq, etc?
sas tabular
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
1
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
1
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
1
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
1
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06
|
show 3 more comments
I have been trying to create a demographic table like below this but I can't seem append the different tables. Please advise on where I can make adjustments in the code.
Group A Group B
chort 1 cohort 2 cohort 3 subtotal cohort 4 cohort 5 cohort 6 subtotal
Age
n
mean
sd
median
min
Gender
n
female
male
Race
n
white
asian
hispanic
black
My Code:
PROC FORMAT;
value content
1=' '
2='Age'
3='Gender'
4='Race'
value sex
1=' n'
2=' female'
3=' male';
value race
1=' n'
2=' white'
3=' asian'
4=' hispanic'
5=' black';
value stat
1=' n'
2=' Mean'
3=' Std. Dev.'
4=' Median'
5=' Minimum';
RUN;
DATA testtest;
SET test.test(keep = id group cohort age gender race);
RUN;
data tottest;
set testtest;
output;
if prxmatch('m/COHORT 1|COHORT 2|COHORT 3/oi', cohort) then do;
cohort='Subtotal';
output;
end;
if prxmatch('m/COHORT 4|COHORT 5|COHORT 6/oi', cohort) then do;
cohort='Subtotal';
output;
end;
run;
data count;
if 0 then set testtest nobs=npats;
call symput('npats',put(npats,1.));
stop;
run;
proc freq data=tottest;
tables cohort /out=patk0 noprint;
tables cohort*sex /out=sex0 noprint;
tables cohort*race /out=race0 noprint;
run;
PROC MEANS DATA = testtest n mean std min median;
class cohort;
VAR age;
RUN;
I know that I would have to transpose it and out it in a report. But before I do that, how do I get the variable out of my proc means, proc freq, etc?
sas tabular
I have been trying to create a demographic table like below this but I can't seem append the different tables. Please advise on where I can make adjustments in the code.
Group A Group B
chort 1 cohort 2 cohort 3 subtotal cohort 4 cohort 5 cohort 6 subtotal
Age
n
mean
sd
median
min
Gender
n
female
male
Race
n
white
asian
hispanic
black
My Code:
PROC FORMAT;
value content
1=' '
2='Age'
3='Gender'
4='Race'
value sex
1=' n'
2=' female'
3=' male';
value race
1=' n'
2=' white'
3=' asian'
4=' hispanic'
5=' black';
value stat
1=' n'
2=' Mean'
3=' Std. Dev.'
4=' Median'
5=' Minimum';
RUN;
DATA testtest;
SET test.test(keep = id group cohort age gender race);
RUN;
data tottest;
set testtest;
output;
if prxmatch('m/COHORT 1|COHORT 2|COHORT 3/oi', cohort) then do;
cohort='Subtotal';
output;
end;
if prxmatch('m/COHORT 4|COHORT 5|COHORT 6/oi', cohort) then do;
cohort='Subtotal';
output;
end;
run;
data count;
if 0 then set testtest nobs=npats;
call symput('npats',put(npats,1.));
stop;
run;
proc freq data=tottest;
tables cohort /out=patk0 noprint;
tables cohort*sex /out=sex0 noprint;
tables cohort*race /out=race0 noprint;
run;
PROC MEANS DATA = testtest n mean std min median;
class cohort;
VAR age;
RUN;
I know that I would have to transpose it and out it in a report. But before I do that, how do I get the variable out of my proc means, proc freq, etc?
sas tabular
sas tabular
edited Nov 20 at 19:25
Brian Tompsett - 汤莱恩
4,1631337100
4,1631337100
asked Nov 20 at 18:59
STL
1157
1157
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
1
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
1
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
1
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
1
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06
|
show 3 more comments
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
1
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
1
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
1
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
1
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
1
1
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
1
1
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
1
1
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
1
1
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06
|
show 3 more comments
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399788%2fsas-demographic-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399788%2fsas-demographic-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I usually write a macro to do these tables. First split your variables into types, which variables need what type of summary, usually that's categorical vs continuous to me, but if you have ordinal or other types you need to consider that. Then I'll build the process for each type and combine them. I have some macros at home...I'll dig them out tonight from when I reported on clinical trials, if you don't have a better answer before that.
– Reeza
Nov 20 at 19:40
1
First, make sure you have working code for at least one variable. Then you can turn your program into a macro :). I have a short tutorial here: github.com/statgeek/SAS-Tutorials/blob/master/…
– Reeza
Nov 20 at 23:52
1
gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67 There's an example of macro usage at the bottom of the page, you'll need to uncomment it. You would replace the macro call with your own. I don't know that this exactly meets your requirements but once you've tested feel free to modify as needed. Good Luck.
– Reeza
Nov 21 at 2:40
1
Personally, I split the file.So split it for one cohort, call the macro. Repeat and then merge the results. You could modify the macro as well, but I was too lazy to do that :)
– Reeza
Nov 27 at 22:41
1
That makes sense! You've been incredibly helpful. Thanks so much!
– STL
Nov 27 at 23:06