Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- proc report computed variable by multiply 2 columns

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-05-2017 05:58 AM
(2076 views)

```
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Bruno,

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.