BookmarkSubscribeRSS Feed
powder
Calcite | Level 5

Using SAS EG 4.3 when I go to divide the two columns the results returned is always zero.  I've tried different formats, etc.  However the same two columns can be added, subtracted, multiplied no issues.  See code and output below for details.  Thanks in advance.

Code:

t1.Region,

          /* TC_Tasks */

            (SUM(t1.MeasureCount)) FORMAT=11. LABEL="TC_Tasks" AS TC_Tasks,

          /* TC_Tasks_Met */

            (SUM(CASE

               WHEN t1.HourDefferedCount <= 4 And MeasureCount = 1 THEN 1

               ELSE 0

            END)) FORMAT=11. LABEL="TC_Tasks_Met" AS TC_Tasks_Met,

          /* TC_Tasks_Met1 */

            ((SUM(CASE

               WHEN t1.HourDefferedCount <= 4 And MeasureCount = 1 THEN 1

               ELSE 0

            END)) / (SUM(t1.MeasureCount))) FORMAT=BEST10.9 LABEL="TC_Tasks_Met1" AS TC_Tasks_Met1,

TC_TasksTC_Tasks_MetTC_Tasks_Met1
5944920
180512750
179112420
5684460
246216560

1 REPLY 1
Linlin
Lapis Lazuli | Level 10

Hi,

I made up a dataset and ran your code. I don't have the problem you described and I ran the code in EG4.3

data test;

input MeasureCount HourDefferedCount;

cards;

1          3

2          4

3          1

0          5

1          6

0          1

1          2

1          3

0          4

1          5

0          6

1          7

;

proc sql;

  select /* TC_Tasks */

            (SUM(t1.MeasureCount)) FORMAT=11. LABEL="TC_Tasks" AS TC_Tasks,

          /* TC_Tasks_Met */

            (SUM(CASE

               WHEN t1.HourDefferedCount <= 4 And MeasureCount = 1 THEN 1

               ELSE 0

            END)) FORMAT=11. LABEL="TC_Tasks_Met" AS TC_Tasks_Met,

          /* TC_Tasks_Met1 */

            ((SUM(CASE

               WHEN t1.HourDefferedCount <= 4 And MeasureCount = 1 THEN 1

               ELSE 0

            END)) / (SUM(t1.MeasureCount))) FORMAT=BEST10.9 LABEL="TC_Tasks_Met1" AS TC_Tasks_Met1

           from test as t1;

quit;

The SAS System

TC_TasksTC_Tasks_MetTC_Tasks_Met1
1130.27272727

and your code is the same as

proc sql;

  select /* TC_Tasks */

            (SUM(t1.MeasureCount)) FORMAT=11. LABEL="TC_Tasks" AS TC_Tasks,

          /* TC_Tasks_Met */

            (SUM(CASE

               WHEN t1.HourDefferedCount <= 4 And MeasureCount = 1 THEN 1

               ELSE 0

            END)) FORMAT=11. LABEL="TC_Tasks_Met" AS TC_Tasks_Met,

          /* TC_Tasks_Met1 */

            calculated TC_Tasks_Met

           / calculated TC_Tasks FORMAT=BEST10.9 LABEL="TC_Tasks_Met1" AS TC_Tasks_Met1

  from test as t1;

quit;

Linlin

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1999 views
  • 0 likes
  • 2 in conversation