BookmarkSubscribeRSS Feed
smartrambit0
Calcite | Level 5

Hi 

I am new to SAS analytics and running my code on "online sas studio". please let me know what is wrong with the code. I am getting missing value for the computed variable.

 

Here is the dataset

--------------------------
data emp;
input id salary total weightr;
datalines;
1 2000 5000 20
2 3000 4000 30
3 5000 7000 44
4 2000 4000 55
;

 

Here is the code

----------------------


proc report data=emp;
column id salary total weightr ratio;
define id / display;
define salary / 'salary';
define total / 'total';
define weightr / 'weight';
define ratio / computed 'ratio';

compute ratio;
ratio=round(weightr/2.2);
endcomp;

run;

 

Below is the output

--------------------------

id salary total weight ratio
1 2000 5000 20         .
2 3000 4000 30         .
3 5000 7000 44         .
4 2000 4000 55         .

 

I am trying to compute ratio as weight/2.2. Please suggest what is wrong with code here.

 

4 REPLIES 4
Reeza
Super User

Add DISPLAY to the DEFINE weightR  statement.

Personally, I also like to explicitly specify the second parameter in the ROUND() function, because it's not the same as the Excel function but people have a tendency to assume it is and it's a common place to make a mistake. 

 

This works for me. 

 

proc report data=emp;
    column id salary total weightr ratio;
    define id / display;
    define salary / 'salary';
    define total / 'total';
    define weightr / display 'weight';
    define ratio / computed 'ratio';
    compute ratio;
        ratio=round(weightr/2.2, 0.1);
    endcomp;
run;

@smartrambit0 wrote:

Hi 

I am new to SAS analytics and running my code on "online sas studio". please let me know what is wrong with the code. I am getting missing value for the computed variable.

 

Here is the dataset

--------------------------
data emp;
input id salary total weightr;
datalines;
1 2000 5000 20
2 3000 4000 30
3 5000 7000 44
4 2000 4000 55
;

 

Here is the code

----------------------


proc report data=emp;
column id salary total weightr ratio;
define id / display;
define salary / 'salary';
define total / 'total';
define weightr / 'weight';
define ratio / computed 'ratio';

compute ratio;
ratio=round(weightr/2.2);
endcomp;

run;

 

Below is the output

--------------------------

id salary total weight ratio
1 2000 5000 20         .
2 3000 4000 30         .
3 5000 7000 44         .
4 2000 4000 55         .

 

I am trying to compute ratio as weight/2.2. Please suggest what is wrong with code here.

 


 

Shmuel
Garnet | Level 18

Next code worked for me:

proc report data=emp;
    column id salary total weightr ratio;
    define id / order 'ID';
    define salary / 'salary';
    define total / 'total';
    define weightr / order 'weight';
    define ratio / computed format 5.1 'ratio';

    break after weightr / ;
    compute ratio;
        ratio=round(weightr/2.2, 0.3);
    endcomp;
run;
smartrambit0
Calcite | Level 5

Perfect thank you. I think, because I did not define it as display variable, SAS treated it as analysis variable as it was numeric datatype.

Due to SAS treating it as analysis variable it was not able to perform mathematical operation on it. 

Shmuel
Garnet | Level 18

Compute can be done only on GROUP or ORDER variable and there is need to define BREAK statement.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1063 views
  • 1 like
  • 3 in conversation