DATA Step, Macro, Functions and more

Define statement

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Define statement


This code is from proc report step before the sorting step.

I have around 20thousand observations in the dataset list_subset_merge2;

trplcd (DRG code) is used to group(condense) those observation into approx 700 in the report.

I want the number of observations(which is 20thousand)....

i use define n

IT SAYS N DOES NOT EXIST IN THE INCOMING DATASET

ods listing;
proc report data=list_subset_merge2 nowindows MISSING  out=rate_calculation(drop=_break_);
columns  rateord trplcd new_description n ('Readmission Rates' Readmit_Numer Readmit_Denom Readmit);
define trplcd /group;
define new_description/group ;
define n/ analysis center;
define Readmit_Numer/sum;
define Readmit_Denom/sum;
define Readmit/computed;
define rateord/computed;

                 compute readmit;
            readmit=readmit_numer.sum/readmit_denom.sum;
      endcomp;

      compute rateord;

    rateord = readmit_numer.sum/readmit_denom.sum;

  endcomp;
  run;
ods listing close;


Accepted Solutions
Solution
‎12-19-2012 11:51 PM
Super User
Posts: 9,662

Re: Define statement

I can replicate your ERRO .

Just remove this statement.

define n/ analysis center;



or code like

define n/ center;

View solution in original post


All Replies
Super Contributor
Posts: 1,040

Re: Define statement

I was thinking n as a statistic would give the number of observations per each TRPLCD

and i can summarize all of them at the very bottom???

Solution
‎12-19-2012 11:51 PM
Super User
Posts: 9,662

Re: Define statement

I can replicate your ERRO .

Just remove this statement.

define n/ analysis center;



or code like

define n/ center;

Super Contributor
Posts: 1,040

Re: Define statement

Thanks a lot.. It WORKS But

I dint understand the meaning of:

I can replicate your ERRO .

Regards

SAS Super FREQ
Posts: 8,739

Re: Define statement

Hi:

  Look at the attached screenshot. ANALYSIS as a USAGE option for N tells PROC REPORT that you have a DATASET variable, named N, that you want to have treated as an ANALYSIS variable and you are asking for the SUM statistic by default. It doesn't matter that you do not have the statistic "SUM", asking for ANALYSIS tells PROC REPORT that N is a DATASET variable. There is an ERROR after the first step because the variable N is NOT in SASHELP.CLASS. This first program seems to be the equivalent of what you did in your program.

   If you want to get the N statistic, then do NOT use the usage of ANALYSIS. Do not use a USAGE at all. See the 2 different programs in the LOG. Without a usage of ANALYSIS, SAS treats N as the N statistic. On the other hand, you need either ANALYSIS MEAN or just MEAN on the DEFINE statements for HEIGHT and WEIGHT so that PROC REPORT knows how you want to use those variables and which statistic you want to generate. As a rule of thumb, I try to avoid having variables named the same as the keyword statistics. But PROC REPORT tried to do what you told it to do -- and when it didn't find a variable called N in the dataset, it gave an ERROR message.

  Understanding USAGE options is critical to working with PROC REPORT successfully.

cynthia


error_on_n.png
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 210 views
  • 1 like
  • 3 in conversation