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.
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.
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;
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.
Compute can be done only on GROUP or ORDER variable and there is need to define BREAK statement.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.