Hi SAS,
I have a dataset contains some character variables and other categorical variables but displaying with numbers. I would like to generate a table the following:
MARITAL_STATUS | ||||
MARITAL_STATUS | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
C | 10 | 0.1 | 10 | 0.1 |
D | 20 | 0.2 | 30 | 0.3 |
M | 30 | 0.3 | 60 | 0.6 |
O | 10 | 0.1 | 70 | 0.7 |
S | 10 | 0.1 | 80 | 0.8 |
W | 20 | 0.2 | 100 | 1 |
I did this using PROC FREQ DATA= ; TABLES _CHARACTER_; RUN;
However, this is only works for thsoe variables which contain chararcter values. For those variables have numeric values, how could I get the similar result? I gave a sample table here as well.
Grade Indicator | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
1 | 10 | 0.1 | 10 | 0.1 |
2 | 20 | 0.2 | 30 | 0.3 |
3 | 30 | 0.3 | 60 | 0.6 |
4 | 10 | 0.1 | 70 | 0.7 |
5 | 10 | 0.1 | 80 | 0.8 |
6 | 20 | 0.2 | 100 | 1 |
Hope anybody can help me. Many appreciation.
Well the obvious answer here is to have character values for those variables which need to have frequency counts performed on them. For instance in my CDISC standards would have:
Grade char(1)
GradeN num
That way you can do both freq and sums.
You could also format the numeric variables:
proc format; value gr 1="1"; run; proc freq...; ... format grade gr.; run;
PROC FREQ runs on numeric variables as well. Just add any you want, as part of the TABLES statement.
And be a little bit careful. If you add a numeric variable that is really continuous rather than categorical, you can generate an extremely long table.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.