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

(I know I should know this). I want to get rid of the hard coded number (10021). This number equals the number of records in the data set.

My objective is to count the number of obs in each efaprimary category listed in the WHERE clause and then get a percentage that it represents of the entire data set. In other words, there are some efaprimary codes not included in the report but I need to count those obs to use in the denominator.

 

proc sql;
SELECT d.efaprimary, count(efaprimary) as Ncount,
calculated Ncount/10021 as Pct format=percent8.2
FROM d45 as d
WHERE enroll_status='0' and grade_level not in ('-1','-2') and efaprimary in ('*DD','*OHI','*PMD','*TBI','AU','EH','EM','HH','LD','OH','SP','TM','VH')
GROUP BY efaprimary;
QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

One way would be to include the total n as a subquerry. e.g.:

proc sql;
  SELECT d.sex, count(sex) as Ncount,
    (select count(*) from sashelp.class) as total,
    calculated Ncount/calculated total as Pct format=percent8.2
      FROM sashelp.class as d
        WHERE age le 12
          GROUP BY sex
  ;
QUIT;

Art, CEO, AnalystFinder.com

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User
proc sql noprint;
select nobs into :nobs from dictionary.tables where libname = 'WORK' and upcase(memname) = 'D45';
quit;

Now you can use &nobs instead of 10021.

GreggB
Pyrite | Level 9

should "info" be "in" ?

art297
Opal | Level 21

One way would be to include the total n as a subquerry. e.g.:

proc sql;
  SELECT d.sex, count(sex) as Ncount,
    (select count(*) from sashelp.class) as total,
    calculated Ncount/calculated total as Pct format=percent8.2
      FROM sashelp.class as d
        WHERE age le 12
          GROUP BY sex
  ;
QUIT;

Art, CEO, AnalystFinder.com

GreggB
Pyrite | Level 9

Thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 870 views
  • 0 likes
  • 3 in conversation