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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 960 views
  • 0 likes
  • 3 in conversation