/* Jump to: Chapter 2 Table of Contents Chapter 4 */
/*
*/
/* Jump to: Next Section */
PROC SQL;
CREATE TABLE teens AS
SELECT name AS FName,
age
FROM sashelp.class
WHERE age>12
;
QUIT;
/* Jump to: Top of Section Top of Chapter */
/* Jump to: Next Section */
PROC FREQ DATA=teens NOPRINT;
TABLES age / OUT=cohorts(DROP=percent RENAME=(count=Many) );
RUN;
PROC SORT DATA=teens OUT=sorted;
BY age;
RUN;
DATA detail_and_counts;
MERGE sorted cohorts;
BY age;
RUN;
PROC SORT DATA=detail_and_counts;
BY fname;
RUN;
PROC SQL;
CREATE TABLE detail_and_counts AS
SELECT fname,
age,
COUNT(*) AS Many
FROM teens
GROUP BY age
ORDER BY fname
;
QUIT;
/* Jump to: Top of Section Top of Chapter */
/* Jump to: Next Section */
PROC MEANS DATA=teens MEAN MAXDEC=3;
VAR age;
RUN;
PROC FREQ DATA=teens NOPRINT;
TABLES age / out=freq2means(KEEP = age);
RUN;
PROC MEANS DATA=freq2means MEAN MAXDEC=3;
VAR age;
RUN;
PROC SQL;
SELECT MEAN( age)
LABEL = 'Weighted' FORMAT=8.3,
MEAN(DISTINCT age)
LABEL = 'Unweighted' FORMAT=8.3
FROM teens
;
QUIT;
PROC SQL;
SELECT DISTINCT MEAN (age) LABEL='DISTINCT MEAN (age)'
FROM teens
;
QUIT;
PROC SQL;
SELECT age
FROM teens
;
QUIT;
/* Jump to: Top of Section Top of Chapter */
/* Jump to: Next Section */
PROC FREQ DATA=teens NOPRINT ORDER=FREQ;
TABLES age / OUT=highlow(DROP=percent RENAME=(count=Many) );
RUN;
DATA largest;
SET highlow;
IF many < LAG(many) THEN STOP;
RUN;
PROC SQL;
CREATE TABLE temp AS
SELECT age,
count(*) AS Many
FROM teens
GROUP BY age
;
CREATE TABLE largest AS
SELECT *
FROM temp
HAVING many = MAX(many)
;
QUIT;
PROC SQL;
CREATE TABLE largest AS
SELECT *
FROM ( SELECT age,
count(*) AS Many
FROM teens
GROUP BY age
)
HAVING many = MAX(many)
;
QUIT;
/* Jump to: Top of Section Top of Chapter */