BookmarkSubscribeRSS Feed
Ayooo1
Obsidian | Level 7

How can I find count and percent using proc sql? EXDSTXT= treatment. The result table shows percent but not by each separate treatment

data:

proc sql noprint;
    create table M_S as 
    select a.SUBJID,b.EXDSTXT,a.SEX,

            case when SEX= 'M' then 'Male'
                 when SEX= 'F' then 'Female'
                 else ''
                 end as sexcatvar,

            case when b.EXDSTXT='7 ug/kg/day' then 1
                 when b.EXDSTXT='9 ug/kg/day' then 2
                 when b.EXDSTXT='12 ug/kg/day' then 3
                 when b.EXDSTXT='Total' then 4
                 else .
                 end as EXDSN
from Sasfile.Dm as a 
inner join EX as b 
on a.SUBJID=b.SUBJID
;
quit;
proc sql noprint;
    create table FREQST as
        select sexcatvar,EXDSN,EXDSTXT,count(sexcatvar) as COUNT,calculated COUNT/ (select count(*) from M_S) as pct format=percent8.2
        from M_S
        group by sexcatvar,EXDSN,EXDSTXT
        order by EXDSTXT;
quit;

result:

 

Ayooo1_1-1673361239800.png

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

That's a lot of work to do this in SQL, all you need to do is the join in PROC SQL and then PROC FREQ computes the statistics much easier

 

proc freq data=have;
    table sex*exdstxt/list;
run;
--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 441 views
  • 1 like
  • 2 in conversation