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
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 save with the early bird rate—just $795!
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.