BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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
BrahmanandaRao
Lapis Lazuli | Level 10

HI Draycut

Brilliant code Thank you very much

Kurt_Bremser
Super User

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;
BrahmanandaRao
Lapis Lazuli | Level 10

Hi 

 

Brilliant code Thank you very much sir

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1390 views
  • 0 likes
  • 3 in conversation