BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10
PROC REPORT DATA = work.T_AMO_CRD_SORTIES nowd ;
	column MOIS_AMO MNT_MOIS_AMO_AVT_SORTIE TX_SORTIE_DDT MNT_MOIS_AMO_SORTIE_DDT , MOIS_PROD_LABEL ;
	define MOIS_AMO / group ;
	define MOIS_PROD_LABEL / across ''  ;
	define MNT_MOIS_AMO_AVT_SORTIE / display noprint;
	define TX_SORTIE_DDT / display noprint;
	define MNT_MOIS_AMO_SORTIE_DDT  / computed f = numx15.5 ;
	COMPUTE MNT_MOIS_AMO_SORTIE_DDT ;
		MNT_MOIS_AMO_SORTIE_DDT = MNT_MOIS_AMO_AVT_SORTIE * TX_SORTIE_DDT ;
		ENDCOMP ;
	title ;
  	RUN ;

Hello,

 

I get 2 columns amount ( )and percentage ( ) and I do not succeed to multiply them.

thanks in advance for your help

Nasser

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Since Proc REPORT builds a report lione by line, we can no longer distingiush the values for the different drivetrains.

 

To get around this, you also need the horsepower and cylinders in your across defintion, so you can do the calculation.

 

For across columns, we can not use the varibale name, but have to use the absolute column number, including the ones that have the NOPRINT option set. See code below:

 

proc report data=newCars;
  column type horsepower Cylinders driveTrain, (horsePower=hp2 cylinders=cyl2 compVar) _dummy;
  define type / group;
  define driveTrain / across;
  define horsepower / analysis ;
  define Cylinders / analysis;
  define compVar / computed f=commax15.;
  define hp2 / analysis noprint;
  define cyl2 / analysis noprint;
  define _dummy / computed noprint;

  compute _dummy;
     _c6_ = _c4_ * _c5_;
     _c9_ = _c7_ * _c8_;
     _c12_ = _c10_ * _c11_;
  endcomp;

run;

Depending on your data, this might not be the most flexible and maintenance friendly way of doing it.

 

Maybe it is better to precalculate all the data, and use Proc REPORT for the display/layout part, see example below:


proc sql;
  create table carsAggr as
  select
    type
    , driveTrain
    , sum(horsePower) as sumhp
    , sum(cylinders) as sumcyl
    , calculated sumhp * calculated sumcyl as mult_hp_cyl
  from
    sashelp.cars
  group by
    type
    , driveTrain
  ;
quit;

proc report data=carsAggr;
  column type sumhp sumcyl mult_hp_cyl, driveTrain;
  define type / group;
  define driveTrain / across;
  define sumhp / analysis f=commax15.;
  define sumcyl / analysis f=commax15.;
  define mult_hp_cyl / analysis f=commax15.;
run;

 

 

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Hi

 

You can not use GROUP and DISPLAY together. I assume you get a note like:

NOTE: Groups are not created because the usage of ..... is DISPLAY. To avoid this note, change all GROUP variables to ORDER variables.

 

Testing this out with data all SAS users have access to to makes things easier.

 

The following code has two examples, first using DISPLAY, so every row will be displayed, the second using ANALYSIS, where data is aggregated on the group varibale. Which one represents waht you need?

proc report data=sashelp.cars(obs=20);
  column type horsepower Cylinders compVar, driveTrain ;
  define type / group;
  define driveTrain / across;
  define horsepower / display ;
  define Cylinders / display;
  define compVar / computed f=commax15.;

  compute compVar;
     compVar = horsePower * Cylinders;
  endcomp;

run;

proc report data=sashelp.cars;
  column type horsepower Cylinders compVar, driveTrain ;
  define type / group;
  define driveTrain / across;
  define horsepower / analysis ;
  define Cylinders / analysis;
  define compVar / computed f=commax15.;

  compute compVar;
     compVar = horsePower * Cylinders;
  endcomp;

run;

 

Nasser_DRMCP
Lapis Lazuli | Level 10

Thanks Bruno,

 

proc report computed.PNG

But  I do not manage to display the computed varaible datas. even if with the example you gave to me. you can notice it in the encmosed screenshot

BrunoMueller
SAS Super FREQ

Since Proc REPORT builds a report lione by line, we can no longer distingiush the values for the different drivetrains.

 

To get around this, you also need the horsepower and cylinders in your across defintion, so you can do the calculation.

 

For across columns, we can not use the varibale name, but have to use the absolute column number, including the ones that have the NOPRINT option set. See code below:

 

proc report data=newCars;
  column type horsepower Cylinders driveTrain, (horsePower=hp2 cylinders=cyl2 compVar) _dummy;
  define type / group;
  define driveTrain / across;
  define horsepower / analysis ;
  define Cylinders / analysis;
  define compVar / computed f=commax15.;
  define hp2 / analysis noprint;
  define cyl2 / analysis noprint;
  define _dummy / computed noprint;

  compute _dummy;
     _c6_ = _c4_ * _c5_;
     _c9_ = _c7_ * _c8_;
     _c12_ = _c10_ * _c11_;
  endcomp;

run;

Depending on your data, this might not be the most flexible and maintenance friendly way of doing it.

 

Maybe it is better to precalculate all the data, and use Proc REPORT for the display/layout part, see example below:


proc sql;
  create table carsAggr as
  select
    type
    , driveTrain
    , sum(horsePower) as sumhp
    , sum(cylinders) as sumcyl
    , calculated sumhp * calculated sumcyl as mult_hp_cyl
  from
    sashelp.cars
  group by
    type
    , driveTrain
  ;
quit;

proc report data=carsAggr;
  column type sumhp sumcyl mult_hp_cyl, driveTrain;
  define type / group;
  define driveTrain / across;
  define sumhp / analysis f=commax15.;
  define sumcyl / analysis f=commax15.;
  define mult_hp_cyl / analysis f=commax15.;
run;

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 2208 views
  • 0 likes
  • 2 in conversation