BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

Hi Guys,

   using the code* below I obtain this:

                            Obsrace     sex  count

                             1 black   female  1
                             2 black   male    2
                             3 latin   female  1
                             4 latin   male    2
                             5 orientalmale    1

code*:

-------------------------------------------------------

data have;

length  subno 4 race $10 sex $10;

input subno race  sex ;

datalines;

1  black male

2  black female

3  latin male

4 latin male

5 black male

6 latin female

7 oriental male

;

run;

proc sql;

create table race as

  select race,  sex

                  ,count(distinct subno) as count

    from have

    group by race, sex;

quit;

proc print data=race; run;

------------------------------------------------------

Anyone can help me to get the final table below using proc sql?....note: (please I know how to get the final table using proc transpose, but I would like to know how to do it with proc sql), thanks.

Final table:

race            male   female     total

black              2      1             3

latin                2      1             3     

oriental           1       0             1

V.

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

OK, proc sql it is:

proc sql;

  select race, sum(sex='male') as male, sum(sex='female') as female, count(race) as total

  from have

  group by race;

quit;

Haikuo

View solution in original post

1 REPLY 1
Haikuo
Onyx | Level 15

OK, proc sql it is:

proc sql;

  select race, sum(sex='male') as male, sum(sex='female') as female, count(race) as total

  from have

  group by race;

quit;

Haikuo

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 8713 views
  • 0 likes
  • 2 in conversation