I have sashelp.class data set like above dataset and how to do group wise analysis in datastep block?
first output:
how to sex wise sum and insert extra record group wise in dataset(we should do data step block only)
for ref:
Why?
Including such summary data in a data set means that you can't use it for almost any purpose except printing. And Proc Report will do that.
or Proc Summary and looking at the proper _type_ values.
proc summary data=sashelp.class; class sex name; var age height weight; types name*sex sex; output out=work.summary (drop=_freq_) sum=; run; proc sort data=work.summary out=work.want (drop=_type_); by sex descending _type_ name; run;
Maxim 14. Don't be stupid and try to reinvent the wheel.
@thanikondharish wrote:
How to do in datastep block
data have;
set sashelp.class;
run;
proc report data=have nowd out=x;
column name sex _sex age height weight;
define name/display;
define sex/order noprint;
define _sex/computed 'sex';
define age/analysis sum;
define height/analysis sum;
define weight/analysis sum;
compute before sex;
temp=sex;
endcomp;
compute _sex/character length=20;
_sex=temp;
endcomp;
compute after sex;
_sex=cats(sex,'-total');
endcomp;
break after sex/summarize;
run;
proc sort data=sashelp.class out=have;
by sex;
run;
data want;
length name sex $ 20;
call missing(_age,_height,_weight);
do until(last.sex);
set have;
by sex;
_age+age;_weight+weight;_height+height;
output;
end;
call missing(name,age,weight,height);
sex=cats(sex,'-total');
age=_age;weight=_weight;height=_height;
output;
drop _:;
run;
Let SAS sequence your data via the power of where:
data want (drop=_:);
set sashelp.class (where=(sex='F'))
sashelp.class (where=(sex='M'));
by sex;
_age+age;
_height+height;
_weight+weight;
output;
if last.sex;
age=_age;
height=_height;
weight=_weight;
name='Total';
output;
call missing(of _:);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.