BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

I have several variables I want to combine into one table.

When I do the following:

 

Proc freq data = ICPNEED.data_allcp;
Table cg_edu1 cg_edu2 cg_edu3 cg_edu4 cg_edu5 cg_edu6 cg_edu7 cg_edu8 cg_edu9 cg_edu10
cg_edu11 cg_edu12 cg_edu13 cg_edu14;
Run;

 

This is the output:

 

gtucke1_0-1653322773780.png

Also, the dataset I received has the variable name and label for each variable. How do I get the label to show up when I do proc freq?

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You could use PROC REPORT or PROC TABULATE to produce results in a single table. But since you don't show us what this single table should look like, I cannot provide code at this time.

 

Regarding your missing labels, if they are not showing up from PROC FREQ, either the labels don't exist, or you have somehow turned on the NOLABEL option, and you need to turn the labels back on with

 

options label;

 

Note: do NOT reply by stating that you have labels in the data set ... if you really think you have labels in the data set then SHOW US the PROC CONTENTS for this ICPNEED.data_allcp data set.

--
Paige Miller
Tom
Super User Tom
Super User

If you have a lot of binary variables like that then why not just use PROC MEANS.

The SUM statistic will show how many 1's there were.

The MEAN statistic will show the percent of 1's there were.

proc means data = ICPNEED.data_allcp n sum mean nmiss;
  var cg_edu1-cg_edu14;
run;
gtucke1
Fluorite | Level 6

Thank you for the help.

 

The database has labels for all of those variables. Is there a way for the label to show up in the table also? Or do I have to manually give a name to all of the variables such as edu_1 = "Alzheimer's Education"

PaigeMiller
Diamond | Level 26

We need to see the PROC CONTENTS output showing the labels.

--
Paige Miller
Tom
Super User Tom
Super User

@gtucke1 wrote:

Thank you for the help.

 

The database has labels for all of those variables. Is there a way for the label to show up in the table also? Or do I have to manually give a name to all of the variables such as edu_1 = "Alzheimer's Education"


What "database"?  I don't know of any databases that really support the SAS concept of variable labels. And even the one's I have seen that have a similar concept (comment fields for example) the SAS engines for those databases do not support converting that metadata into SAS variable labels.

 

If the information is available then use it to generate the label statement so that your SAS dataset will have labels attached to the variable.  For example if you could create a dataset with two fields NAME and LABEL for every variable in a dataset you could use that to generate a LABEL statement you could use to update your SAS dataset's metadata.

 

So if you dataset is named WORK.HAVE and the dataset with the name/label pairs is named METADATA then you can use code like this.

filename code temp;
data _null_;
   set metadata end=eof;
  if _n_=1 then put 'label';
  if name ne label then  put name '=' label :$quote. ;
  if eof then put ';';
run;
proc datasets lib=work nolist;
  modify have;
%include code / list;
  run;
quit;
ballardw
Super User

Likely Proc Report or Tabulate will do what you need if you show what you want.

You can get the output from proc freq into data sets that can be manipulated/printed to get output in a single report table as well. A small example:

 

ods output onewayfreqs=myfreqtable;
proc freq data=sashelp.class;
   tables sex age;
run;

options missing=' ';
data toprint;
   set myfreqtable;
   table=scan(table,2);
   Category= cats(sex,age);
   keep table category frequency cumfrequency percent cumpercent;
run;
options missing='.';
proc print data=toprint noobs label;
   var table category frequency cumfrequency percent cumpercent;
run;

I won't go into a lot of detail but the ODS OUTPUT will place all the data of one type into a data set. ONEWAYFREQS are the basic table, minus missing information, of counts and percentages. Each option on the tables statement that creates different tables have different table names you can use in the ODS OUTPUT to capture the values. The appearance however will differ somewhat than is displayed in the Results window.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1689 views
  • 0 likes
  • 4 in conversation