WE HAVE A SAS DATA SET:
EMP_ID NAME SALARY SALARY/TOTAL
-----------------------------------------------------------------------------------------------
101 RAM 500 500/4700
102 SITA 600 600/4700
103 RADHA 700 700/4700
104 RAVAN 800 800/4700
105 ARJUN 900 900/4700
106 BHIM 1000 1000/4700
Now prepare your Base SAS and
Advance SAS Certification Exams with Online Mock tests: http://exam.sankhyana.com
For training related info kindly mail us at info@sankhyana.com
www.sankhyana.com
ONE
EMP_ID NAME SALARY
-----------------------------------------------------
101 RAM 500
102 SITA 600
103 RADHA 700
104 RAVAN 800
105 ARJUN 900
106 BHIM 1000
WE NEED TO CREATE ANOTHER SAS DATA SET:
-----------------------------------------------------------------------------------------------
101 RAM 500 500/4700
102 SITA 600 600/4700
103 RADHA 700 700/4700
104 RAVAN 800 800/4700
105 ARJUN 900 900/4700
106 BHIM 1000 1000/4700
Now prepare your Base SAS and
Advance SAS Certification Exams with Online Mock tests: http://exam.sankhyana.com
For training related info kindly mail us at info@sankhyana.com
www.sankhyana.com
I believe the total salary will be 4500 instead of 4700. Please correct if i am wrong. Please try the below code to get the desired output
ReplyDeletedata have;
input id name$ salary;
sum+salary;
cards;
101 RAM 500
102 SITA 600
103 RADHA 700
104 RAVAN 800
105 ARJUN 900
106 BHIM 1000
;
run;
data have_;
set have;
by id;
if last.id then call symputx("tot",sum);
div=cat(put(salary,8.),"/",&tot);
run;
Please let me know if this is not the output you were expecting.
Thanks,
Jagadish
ReplyDeletedata one;
infile datalines;
input emp_id name$ salary;
datalines;
101 RAM 500
102 SITA 600
103 RADHA 700
104 RAVAN 800
105 ARJUN 900
106 BHIM 1000
;
run;
proc sql;
select emp_id, name, salary, salary/sum(salary) 'salary/total' format=percent7.
from one;
quit;
data one;
infile datalines;
input emp_id name$ salary;
datalines;
101 RAM 500
102 SITA 600
103 RADHA 700
104 RAVAN 800
105 ARJUN 900
106 BHIM 1000
;
run;
/*/*proc sql;*/*/
/*select emp_id, name, salary, salary/sum(salary) 'salary/total' format=percent7.*/
/*from one;*/
/*quit;*/ ;
proc means data=one sum noprint ;
var salary;
output out=two sum=total;
run;
data three;
merge one two (drop=_type_ _freq_);
retain totalsal 0;
if _n_=1 then totalsal=total;
saltot=salary/totalsal;
keep emp_id name salary saltot;
format saltot percent6.;
run;
proc print data=three;
run;
data one;
ReplyDeleteinput emp_id name$ salary;
datalines;
101 RAM 500
102 SITA 600
103 RADHA 700
104 RAVAN 800
105 ARJUN 900
106 BHIM 1000
;
run;
proc sql;
select emp_id, name, salary, cat(salary,"/",sum(salary)) 'SALARY/TOTAL'
from one;
quit;
data two(keep= emp_id name salary totalsal);
ReplyDeleteif _n_=1 then do i =1 to x;
set one nobs=x;
y+salary;
end;
set one;
totalsal=salary/y;
run;
proc print data=two noobs;
format totalsal percent5.;
run;