BookmarkSubscribeRSS Feed
RRzio11
Calcite | Level 5

Hello

 

I am trying to proc tabulate by age groups. I formatted my dataset by the following groups:

 

proc format;

value age_cat
20-39="20>39"
40-49="40>49"
50-59="50>59"
60-200= ">60"
.="Missing age"
;

 

and then put this as my proc tabulate code:

PROC SORT DATA=NHM1514; BY AGE; RUN;
proc tabulate data=nhm1514;
CLASS AGE;
var GENDER smoking martial education diabetes blood_pressure hiv bmi crp SHBG EST TST WBC ORXH06 ORXH11 ORXH16
ORXH18 ORXH26 ORXH31 ORXH33 ORXH35 ORXH39 ORXH40 ORXH42 ORXH45 ORXH51 ORXH52 ORXH53 ORXH54 ORXH55 ORXH56 ORXH58 ORXH59 ORXH61 ORXH62 ORXH64 ORXH66 ORXH67
ORXH68 ORXH69 ORXH70 ORXH71 ORXH72 ORXH73 ORXH81 ORXH82 ORXH83 ORXH84 LBDR06 LBDR11 LBDR16 LBDR18 LBDR26 LBDR31 LBDR33 LBDR35 LBDR39 LBDR40 LBDR42 LBDR45
LBDR51 LBDR52 LBDR53 LBDR54 LBDR55 LBDR56 LBDR58 LBDR59 LBDR61 LBDR62 LBDR64 LBDR66 LBDR67 LBDR68 LBDR69 LBDR70 LBDR71 LBDR72 LBDR73 LBDR81 LBDR82 LBDR83
LBDR84 LBDR89 HPVP06 HPVP11 HPVP16 HPVP18 HPVP26 HPVP31 HPVP33 HPVP35 HPVP39 HPVP40 HPVP42 HPVP45 HPVP51 HPVP52 HPVP53 HPVP54 HPVP55 HPVP56 HPVP58 HPVP59
HPVP61 HPVP62 HPVP64 HPVP66 HPVP67 HPVP68 HPVP69 HPVP70 HPVP71 HPVP72 HPVP73 HPVP81 HPVP82 HPVP83 HPVP84 HPVP89;
table ( GENDER smoking martial education diabetes blood_pressure hiv bmi SHBG EST TST WBC ORXH06 ORXH11 ORXH16
ORXH18 ORXH26 ORXH31 ORXH33 ORXH35 ORXH39 ORXH40 ORXH42 ORXH45 ORXH51 ORXH52 ORXH53 ORXH54 ORXH55 ORXH56 ORXH58 ORXH59 ORXH61 ORXH62 ORXH64 ORXH66 ORXH67
ORXH68 ORXH69 ORXH70 ORXH71 ORXH72 ORXH73 ORXH81 ORXH82 ORXH83 ORXH84 LBDR06 LBDR11 LBDR16 LBDR18 LBDR26 LBDR31 LBDR33 LBDR35 LBDR39 LBDR40 LBDR42 LBDR45
LBDR51 LBDR52 LBDR53 LBDR54 LBDR55 LBDR56 LBDR58 LBDR59 LBDR61 LBDR62 LBDR64 LBDR66 LBDR67 LBDR68 LBDR69 LBDR70 LBDR71 LBDR72 LBDR73 LBDR81 LBDR82 LBDR83
LBDR84 LBDR89 HPVP06 HPVP11 HPVP16 HPVP18 HPVP26 HPVP31 HPVP33 HPVP35 HPVP39 HPVP40 HPVP42 HPVP45 HPVP51 HPVP52 HPVP53 HPVP54 HPVP55 HPVP56 HPVP58 HPVP59
HPVP61 HPVP62 HPVP64 HPVP66 HPVP67 HPVP68 HPVP69 HPVP70 HPVP71 HPVP72 HPVP73 HPVP81 HPVP82 HPVP83 HPVP84 HPVP89)*(N MEAN STD pctn), gender ALL;
run;

 

but then i get 496 error messages on my log:

ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * N * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * Mean * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * Std * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * PctN * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : SMOKING * N * GENDER.
 
Can you help me understand what I am doing wrong and how to appropriately code by variable groups?
1 REPLY 1
ballardw
Super User

@RRzio11 wrote:

Hello

 

I am trying to proc tabulate by age groups. I formatted my dataset by the following groups:

 

proc format;

value age_cat
20-39="20>39"
40-49="40>49"
50-59="50>59"
60-200= ">60"
.="Missing age"
;

 

and then put this as my proc tabulate code:

PROC SORT DATA=NHM1514; BY AGE; RUN;
proc tabulate data=nhm1514;
CLASS AGE;
var GENDER smoking martial education diabetes blood_pressure hiv bmi crp SHBG EST TST WBC ORXH06 ORXH11 ORXH16
ORXH18 ORXH26 ORXH31 ORXH33 ORXH35 ORXH39 ORXH40 ORXH42 ORXH45 ORXH51 ORXH52 ORXH53 ORXH54 ORXH55 ORXH56 ORXH58 ORXH59 ORXH61 ORXH62 ORXH64 ORXH66 ORXH67
ORXH68 ORXH69 ORXH70 ORXH71 ORXH72 ORXH73 ORXH81 ORXH82 ORXH83 ORXH84 LBDR06 LBDR11 LBDR16 LBDR18 LBDR26 LBDR31 LBDR33 LBDR35 LBDR39 LBDR40 LBDR42 LBDR45
LBDR51 LBDR52 LBDR53 LBDR54 LBDR55 LBDR56 LBDR58 LBDR59 LBDR61 LBDR62 LBDR64 LBDR66 LBDR67 LBDR68 LBDR69 LBDR70 LBDR71 LBDR72 LBDR73 LBDR81 LBDR82 LBDR83
LBDR84 LBDR89 HPVP06 HPVP11 HPVP16 HPVP18 HPVP26 HPVP31 HPVP33 HPVP35 HPVP39 HPVP40 HPVP42 HPVP45 HPVP51 HPVP52 HPVP53 HPVP54 HPVP55 HPVP56 HPVP58 HPVP59
HPVP61 HPVP62 HPVP64 HPVP66 HPVP67 HPVP68 HPVP69 HPVP70 HPVP71 HPVP72 HPVP73 HPVP81 HPVP82 HPVP83 HPVP84 HPVP89;
table ( GENDER smoking martial education diabetes blood_pressure hiv bmi SHBG EST TST WBC ORXH06 ORXH11 ORXH16
ORXH18 ORXH26 ORXH31 ORXH33 ORXH35 ORXH39 ORXH40 ORXH42 ORXH45 ORXH51 ORXH52 ORXH53 ORXH54 ORXH55 ORXH56 ORXH58 ORXH59 ORXH61 ORXH62 ORXH64 ORXH66 ORXH67
ORXH68 ORXH69 ORXH70 ORXH71 ORXH72 ORXH73 ORXH81 ORXH82 ORXH83 ORXH84 LBDR06 LBDR11 LBDR16 LBDR18 LBDR26 LBDR31 LBDR33 LBDR35 LBDR39 LBDR40 LBDR42 LBDR45
LBDR51 LBDR52 LBDR53 LBDR54 LBDR55 LBDR56 LBDR58 LBDR59 LBDR61 LBDR62 LBDR64 LBDR66 LBDR67 LBDR68 LBDR69 LBDR70 LBDR71 LBDR72 LBDR73 LBDR81 LBDR82 LBDR83
LBDR84 LBDR89 HPVP06 HPVP11 HPVP16 HPVP18 HPVP26 HPVP31 HPVP33 HPVP35 HPVP39 HPVP40 HPVP42 HPVP45 HPVP51 HPVP52 HPVP53 HPVP54 HPVP55 HPVP56 HPVP58 HPVP59
HPVP61 HPVP62 HPVP64 HPVP66 HPVP67 HPVP68 HPVP69 HPVP70 HPVP71 HPVP72 HPVP73 HPVP81 HPVP82 HPVP83 HPVP84 HPVP89)*(N MEAN STD pctn), gender ALL;
run;

 

but then i get 496 error messages on my log:

ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * N * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * Mean * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * Std * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : GENDER * PctN * GENDER.
ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : SMOKING * N * GENDER.
 
Can you help me understand what I am doing wrong and how to appropriately code by variable groups?

 

In the code you show the only variable that can have the role of a "group" variable is AGE. Any variable on the VAR statement is an analysis variable and will have statistic calculated for it.

However Proc Tabulate does not allow you to "cross" var varaibles against each other because each needs a statistic and the intent of which is desired is not clear in that case.

If you want Gender as group variable then 1) remove it from the VAR statement, 2) place it in a CLASS statement, and 3) remove it from the parenthesized variables in the Table statement.

 

While VAR variables must be numeric you can use numeric variables as Class variables. A format such as you show is one of the nice ways to create usable categories from a variable with many levels.

 

I suspect that you missed a FORMAT age age_cat.; and from your sort you likely intended a BY Age; in proc tabulate as well.

 

I would suspect that marital and education should more likely be Class variables and if smoking, diabetes and hiv are indicators of history of smoking, have/do not have diabetes or hiv that they are more likely candidates as class variables.

 

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!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 455 views
  • 0 likes
  • 2 in conversation