Hi all,
For simple 1-way frequencies I know Proc Freq can do all variables in a data set if I just don't specify anything in the table option.
But I would like to create 2-by-2 tables with say variable Z.
So if my data set have columns W X Y Z, I would do:
Proc freq data = have;
table W*Z X*Z Y*Z;
run;
But my data set has like 70 variables. I was wondering if there is a way to this with all variables, or all but certain variables.
Thanks,
Jacky
You have a few options.
1. If the variables are all in order in the table (column order) you can list the first and last variables only, with double hyphens in between (--).
proc freq data=sashelp.heart (obs=50); table ageAtStart *(bp_status--smoking_status); run;
2. If the variables have a similar prefix you can use the colon short cut notation
proc freq data=sashelp.heart (obs=50); table ageAtStart *(chol:); run;
3. If neither applies you can list all, though you'll get one extra table of X*X. _all_ refers to all variables, _numeric_ all numeric and _character_ is all character variables.
proc freq data=sashelp.heart (Obs=50);
table ageAtStart * (_all_);
table ageAtStart * (_numeric_);
table ageAtStart * (_character_);
run;
@JackyK wrote:
Hi all,
For simple 1-way frequencies I know Proc Freq can do all variables in a data set if I just don't specify anything in the table option.
But I would like to create 2-by-2 tables with say variable Z.
So if my data set have columns W X Y Z, I would do:
Proc freq data = have; table W*Z X*Z Y*Z; run;
But my data set has like 70 variables. I was wondering if there is a way to this with all variables, or all but certain variables.
Thanks,
Jacky
You have a few options.
1. If the variables are all in order in the table (column order) you can list the first and last variables only, with double hyphens in between (--).
proc freq data=sashelp.heart (obs=50); table ageAtStart *(bp_status--smoking_status); run;
2. If the variables have a similar prefix you can use the colon short cut notation
proc freq data=sashelp.heart (obs=50); table ageAtStart *(chol:); run;
3. If neither applies you can list all, though you'll get one extra table of X*X. _all_ refers to all variables, _numeric_ all numeric and _character_ is all character variables.
proc freq data=sashelp.heart (Obs=50);
table ageAtStart * (_all_);
table ageAtStart * (_numeric_);
table ageAtStart * (_character_);
run;
@JackyK wrote:
Hi all,
For simple 1-way frequencies I know Proc Freq can do all variables in a data set if I just don't specify anything in the table option.
But I would like to create 2-by-2 tables with say variable Z.
So if my data set have columns W X Y Z, I would do:
Proc freq data = have; table W*Z X*Z Y*Z; run;
But my data set has like 70 variables. I was wondering if there is a way to this with all variables, or all but certain variables.
Thanks,
Jacky
Thank you, it was really helpful to know these tricks with variables as they can probably be applied in other Proc's.
@JackyK wrote:
Hi all,
For simple 1-way frequencies I know Proc Freq can do all variables in a data set if I just don't specify anything in the table option.
But I would like to create 2-by-2 tables with say variable Z.
So if my data set have columns W X Y Z, I would do:
Proc freq data = have; table W*Z X*Z Y*Z; run;
But my data set has like 70 variables. I was wondering if there is a way to this with all variables, or all but certain variables.
Thanks,
Jacky
You may want to think about how many values per variable are involved and now many tables (70*70= 4900) you will generate as you quite possibly can fill up a results window or spend a long time waiting for the tables to render.
I remember a job similar to this at one place I worked when all output was sent to a line printer. And finding 8 full paper boxes of output waiting.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.