Help using Base SAS procedures

proc report repeat the group value for each lines

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 117
Accepted Solution

proc report repeat the group value for each lines

	PROC REPORT DATA = work.BEH_AGG_5  ;
	column RAC  Groupe GENERATION production ANNEE_AMO, CRD_GEN_MENS_MEAN  ;
	define RAC / group   ;
	define Groupe / group   ;
	define GENERATION / group  ;
	define production / group  ;
	define ANNEE_AMO /   across  ;
	define CRD_GEN_MENS_MEAN / '' f=12.2 ;
	title ;
  	RUN ;

 

Hello,


By launch this code, the indicators CRD_GEN_MENS_MEAN are correctly aligned in one line correspoinf to a combination of group variables. the problem is that the value of RAC is displayed only once (first row).

I would like to display it one each row. so I specified display as "define RAC / group display ; "


and then the RAC value is effectively repeated but now , the indicators CRD_GEN_MENS_MEAN values are not aligned anymore.
thanks a lot in adcance for your help


Accepted Solutions
Solution
‎08-25-2017 09:30 AM
Frequent Contributor
Posts: 117

Re: PROC Report repeating grroup varaibale values

Posted in reply to Nasser_alfea

thanks for your quick respons. I found the solution insisde proc report by using a compute like this :

 

COMPUTE RAC ;

IF RAC NE ' ' then hold=RAC ;

IF RAC EQ ' ' then RAC=hold ;

ENDCOMP;

 

then in the clumn RAC, the first value is repeated

 

View solution in original post


All Replies
Frequent Contributor
Posts: 117

PROC Report repeating grroup varaibale values

Posted in reply to Nasser_alfea

 

PROC REPORT DATA = work.BEH_AGG_5 nowd  ;
	column RAC Groupe GENERATION production ANNEE_AMO, CRD_GEN_MENS_MEAN  ;
	define RAC / group ;
	define Groupe / group   ;
	define GENERATION / group  ;
	define production / group  ;
	define ANNEE_AMO / across  ;
	define CRD_GEN_MENS_MEAN / '' f=12.2 ;
	title ;
  	RUN ;

 

 

hello,

I would like to get a report with the column "year" transposed and with the variable group values repeated.
with the enclosed code, I succeed to get the indicators values aligned on the same line (this is intended). but the value of group variable is only once displayed (first row).
by specifying "display" like this  "define RAC / group display ;" the values are repeated (not sorted) but indicators are no aligned anymore.

thanks a lot for your help

Solution
‎08-25-2017 09:30 AM
Frequent Contributor
Posts: 117

Re: PROC Report repeating grroup varaibale values

Posted in reply to Nasser_alfea

thanks for your quick respons. I found the solution insisde proc report by using a compute like this :

 

COMPUTE RAC ;

IF RAC NE ' ' then hold=RAC ;

IF RAC EQ ' ' then RAC=hold ;

ENDCOMP;

 

then in the clumn RAC, the first value is repeated

 

SAS Super FREQ
Posts: 825

Re: proc report repeat the group value for each lines

Posted in reply to Nasser_alfea

Since the value for GROUP value is only displayed once, you have to put it aside.

 

For this you need some logic in Proc REPORT, see sample below. However if you just need that data to be then exported, see the Proc SQL and Proc TRANSPOSE code below.

 

proc report data=sashelp.cars;
  column type displayType driveTrain origin, msrp _dummy;
  define type / group noprint;
  define driveTrain / group;
  define displayType / computed ;
  define origin / across;
  define msrp / analysis;
  define _dummy / computed noprint;

  compute displayType / char length=32;
  endcomp;

  compute _dummy / char length=32;
    if type ne " " then do;
      tempName = type;
    end;
    _dummy = tempName;
    displayType = tempName;
  endcomp;
run;

proc sql;
  create table cars_aggr as
  select
    type, driveTrain, origin, sum(msrp) as msrp_sum
  from 
    sashelp.cars
  group by
    type, driveTrain, origin
  order by
    type, driveTrain, origin
  ;
quit;

proc transpose
  data=cars_aggr
  out=cars_trsp
;
  by type driveTrain;
  var msrp_sum;
  id origin;
run;
☑ This topic is solved.

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

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