BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnHoughton
Quartz | Level 8

If my dataset variables are the names of statistics (e.g mean min max) , is there no built-in way to use those variables in proc report columns, At the moment I am renaming the variables so they are no longer statistic names. The only reference I've been able to find does the same ,renaming "mean" to "xmean", "std" to "xstd" etc, "so proc report does not get confused"

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First would be why are you creating variables with those names in first place.

 

Second might be to share the sort of Proc Report you are creating. The issue with report is can the procedure tell that a keyword is only used as variable name or not. It is okay to have a variable named "mean" as long as you don't ask Proc Report to calculate a mean for anything.

An example of using a variable named mean in Proc report. Note that if you do not explicitly include a DEFINE statement then SAS does not know that you intend the Mean that appears on the column statement to be a variable and will complain.

data example;
  do i= 1 to 5;
   do j= 1 to 20;
     mean= rand('uniform');
     output;
   end;
  end;
run;

proc report data=example;
   column i mean,(min  max) ;
   define i/group;
   define mean / analysis;
run;

As soon as you want the mean of another variable you can't use it on the column statement. But a specific define may get you around that:

data example;
  do i= 1 to 5;
   do j= 1 to 20;
     mean= rand('uniform');
     y   = rand('uniform');
     output;
   end;
  end;
run;

proc report data=example;
   column i mean,(min  max) y;
   define i/group;
   define mean / analysis;
   define y /mean;
run;

 

It may just be easier in the long run to quit naming variables with keywords.

View solution in original post

3 REPLIES 3
ballardw
Super User

First would be why are you creating variables with those names in first place.

 

Second might be to share the sort of Proc Report you are creating. The issue with report is can the procedure tell that a keyword is only used as variable name or not. It is okay to have a variable named "mean" as long as you don't ask Proc Report to calculate a mean for anything.

An example of using a variable named mean in Proc report. Note that if you do not explicitly include a DEFINE statement then SAS does not know that you intend the Mean that appears on the column statement to be a variable and will complain.

data example;
  do i= 1 to 5;
   do j= 1 to 20;
     mean= rand('uniform');
     output;
   end;
  end;
run;

proc report data=example;
   column i mean,(min  max) ;
   define i/group;
   define mean / analysis;
run;

As soon as you want the mean of another variable you can't use it on the column statement. But a specific define may get you around that:

data example;
  do i= 1 to 5;
   do j= 1 to 20;
     mean= rand('uniform');
     y   = rand('uniform');
     output;
   end;
  end;
run;

proc report data=example;
   column i mean,(min  max) y;
   define i/group;
   define mean / analysis;
   define y /mean;
run;

 

It may just be easier in the long run to quit naming variables with keywords.

JohnHoughton
Quartz | Level 8

Thanks ballardw, Looks like I was doing the best thing by renaming the variable then, but explicitly using the define statement is an alternative.


@ballardw wrote:

First would be why are you creating variables with those names in first place.

.

.

It may just be easier in the long run to quit naming variables with keywords.


 

I didn't create the variable ; SAS did, in an ODS table. My original problem came about because I was using proc report on a data set produced using ODS output from proc mixed, but the ODS table includes the variable StdErr, which is one of the statistic keywords.

 

My fix was to rename StdErr. But the on-line SAS help for proc report gives the impression that there may be another solution.

(From "Statistics That Are Available in PROC REPORT")

 

Note: If a variable name (class or analysis) and a statistic name are the same, then enclose the statistic name in single quotation marks (for example, 'MAX').

But it looks like this proc report help page has been copied from PROC TABULATE without editing the content (the giveaway being it mentions the TABLE statement). 

JohnHoughton
Quartz | Level 8

The error in the online help for Proc Report has been corrected now

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1683 views
  • 0 likes
  • 2 in conversation