Hi Experts Good Evening
I am want output like below format in log window
Total_Female=9
Total_Male=10
/*How to find total count with Gender_wise*/
data ds;
set sashelp.class;
run;
proc sort data=ds;
by sex;
run;
data sex_count(keep=sex Gender_wise_total_count);
set ds ;
by sex ;
if first.sex then Gender_wise_total_count=0;
Gender_wise_total_count+1;
if last.sex ;
put Total_Gender_wise_total_count=Gender_wise_total_count;
run;
Here is one way
proc sort data=sashelp.class out=ds;
by sex;
run;
data _null_;
do total=1 by 1 until (last.sex);
set ds;
by sex;
end;
put "Total_"sex"=" total;
run;
Result in log:
Total_F =9 Total_M =10
Here is one way
proc sort data=sashelp.class out=ds;
by sex;
run;
data _null_;
do total=1 by 1 until (last.sex);
set ds;
by sex;
end;
put "Total_"sex"=" total;
run;
Result in log:
Total_F =9 Total_M =10
HI Draycut
Brilliant code Thank you very much
Different approach using proc freq:
proc freq data=sashelp.class;
tables sex / out=sum (keep=sex count);
run;
proc format;
value $sexfmt
"F" = "Female"
"M" = "Male"
;
run;
data _null_;
set sum;
outstring = cats(catx(" ",'Total',put(sex,$sexfmt.)),"=",count);
put outstring;
run;
Hi KurtBremser
Brilliant code Thank you very much sir
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.