How to simplify PROC REPORT steps?

Reply
Contributor
Posts: 68

How to simplify PROC REPORT steps?

proc report data=learn.Survey nowd headline;

column ID Age Gender Salary Ques1-Ques5 Response;

define ID/ width=3;

define Age/ display width=3;

define Gender/ width=7;

define Salary/ display format=dollar8.;

define Ques1/ display noprint;

define Ques2/ display noprint;    Hi guys, is it possible to use one sentence to achieve

define Ques3/ display noprint;       the same result as the 5 sentences did here? Thank you!

define Ques4/ display noprint;

define Ques5/ display noprint;

define Response/ Computed 'Average Response' width=8;

compute Response;proc

Response=mean(of Ques1-Ques5);

endcomp;

run;

quit;

Super User
Posts: 11,104

Re: How to simplify PROC REPORT steps?

You might display what you want for output. Without data we can't really duplicate the appearance you get.

Contributor
Posts: 68

Re: How to simplify PROC REPORT steps?

I created a simple dataset:

ID Ques1 Ques2 Ques3 Ques4 Ques5

535 1 3 5 4 2

012 5 5 4 4 3

723 2 1 2 1 1

007 3 5 1 4 2

the result I want to achieve is

Subj

Average

Response

5353
0124.2
7231.4
0073
Respected Advisor
Posts: 3,786

Re: How to simplify PROC REPORT steps?

define quest1-quest5 / display noprint;
Contributor
Posts: 68

Re: How to simplify PROC REPORT steps?

Hi data_null_, I tested it on the dataset, however this technique seems do not work within proc report statement.

Respected Advisor
Posts: 3,786

Re: How to simplify PROC REPORT steps?

I tested it too and it does work.  Show your code.

Contributor
Posts: 68

Re: How to simplify PROC REPORT steps?

I used the dataset sent to ballardw.

the code I used:

proc report data=learn.Survey1 nowd headline;

column Subj Q1-Q5 Response;

define Subj/ width=3;

define Q1-Q5 / display noprint;

define Response/ Computed 'Average Response' width=8;

compute Response;

Response=mean(of Q1-Q5);

endcomp;

run;

quit;

the log showed:

222  define Subj/ width=3;

223  define Q1-Q5 / display noprint;

              -

              79

              200

ERROR 79-322: Expecting a /.

ERROR 200-322: The symbol is not recognized and will be ignored.

224  define Response/ Computed 'Average Response' width=8;

225  compute Response;

226  Response=mean(of Q1-Q5);

227  endcomp;

228  run;

Respected Advisor
Posts: 3,786

Re: How to simplify PROC REPORT steps?

data test;
   input ID:$3. Ques1 Ques2 Ques3 Ques4 Ques5;
   cards;
535 1 3 5 4 2
012 5 5 4 4 3
723 2 1 2 1 1
007 3 5 1 4 2
;;;;
proc report nowd list;
  
columns id ques1-ques5;
   define id / width=3;
  
define ques1-ques5 / display;
  
run;

41         proc report nowd list;
42            columns id ques1-ques5;
43            define id / width=3;
44            define ques1-ques5 / display;
45            run;

PROC REPORT DATA=WORK.TEST LS=132 PS=60  SPLIT="/" CENTER ;
COLUMN  ( ID Ques1 Ques2 Ques3 Ques4 Ques5 );

DEFINE  ID / DISPLAY FORMAT= $3. WIDTH=3     SPACING=2   LEFT "ID" ;
DEFINE  Ques1 / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Ques1" ;
DEFINE  Ques2 / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Ques2" ;
DEFINE  Ques3 / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Ques3" ;
DEFINE  Ques4 / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Ques4" ;
DEFINE  Ques5 / DISPLAY FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Ques5" ;
RUN;

NOTE:
There were 4 observations read from the data set WORK.TEST.
NOTE: PROCEDURE REPORT used (Total process time):
      real time          
0.05 seconds
      cpu time           
0.06 seconds
     
Super User
Posts: 3,233

Re: How to simplify PROC REPORT steps?

According to SAS documentation the ability to use a variable list - var1-var99 - in a DEFINE statement started with SAS 9.3. What version of SAS are you using?

Ask a Question
Discussion stats
  • 8 replies
  • 293 views
  • 0 likes
  • 4 in conversation