Hello,
I want to create a table (please see an attached file) from the data set below:
DATA data1;
input id age sex exp;
DATALINES;
1 1 1 0
2 2 2 1
3 3 2 0
4 1 2 1
5 1 1 1
6 3 1 1
7 1 1 0
8 2 2 0
9 1 1 0
;
run;
I can get numbers running multiple 'proc freq';
proc sort data=data1 out=data1_sort; by exp; run;
proc freq data=data1_sort;
table age sex;
run;
proc freq data=data1_sort;
table age;
by exp;
run;
proc freq data=data1_sort;
table sex;
by exp;
run;
But, I have to copy and paste the results.
Is there a way(s) to get the table directly from the data set without copying and pasting results?
Thank you,
Yoko
Like this?
proc freq data=DATA1_SORT;
table AGE / out=AGE;
by EXP;
run;
Sure, where you do you want the results, PDF or RTF (will open as word document) or Excel?
ods pdf file='/folders/myfolders/myPDF.pdf' style=journal;
ods excel file = '/folders/myfolders/myExcel.xlsx' style = journal;
ods rtf file = '/folders/myfolders/myRTF.rtf' style=journal;
proc freq data=data1_sort;
table age sex;
run;
proc freq data=data1_sort;
table age;
by exp;
run;
proc freq data=data1_sort;
table sex;
by exp;
run;
ods rtf close;
ods pdf close;
ods excel close;
@Yoko wrote:
Hello,
I want to create a table (please see an attached file) from the data set below:
DATA data1;
input id age sex exp;
DATALINES;
1 1 1 0
2 2 2 1
3 3 2 0
4 1 2 1
5 1 1 1
6 3 1 1
7 1 1 0
8 2 2 0
9 1 1 0
;
run;
I can get numbers running multiple 'proc freq';
proc sort data=data1 out=data1_sort; by exp; run;
proc freq data=data1_sort;
table age sex;
run;
proc freq data=data1_sort;
table age;
by exp;
run;
proc freq data=data1_sort;
table sex;
by exp;
run;
But, I have to copy and paste the results.
Is there a way(s) to get the table directly from the data set without copying and pasting results?
Thank you,
Yoko
It would help to provide some example data.
Also the forum seems to be having an issue with allowing us to see attachments as yours is appearing with a "virus scan running" and is unavailable at this time. It may mean that you need to post the attached in a different file format.
Do you actually need the cumulative counts and percentages for the Age and Sex one-way tables?
If you don't need the cumulative bits perhaps proc tabulate will work though the age by sex table would look a bit different.
Here is one example using a created data set to have similar variables that might get you started:
data example; set sashelp.class; exp = rand('table',.3,.7); run; proc tabulate data=example; class exp age sex; table age, sex*(n pctn colpctn rowpctn);
table age all, sex all; table exp, age,(n colpctn); table exp, sex,(n colpctn); run;
A big caveat for using proc tabulate in this manner is if any of the variables that appear on a CLASS statement have missing values then by default the entire record is excluded from the counts.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.