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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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