G'day,
I have the following program: Part 1 & 2 runs without SAS errors except Part 3 doesn't run. I'm trying to add pctud so that is shows under type (i.e, ask SAS to calculate pctutd across the two different types) and also ask SAS to calculate it for the combined types (which is equivalent to pctutd in Part 2) so it will have 3 columns with pctutd: the first column (after locale, year, grade, and children) with pctutd that sums utd for all types (type=class & nonclass) and divides it by the totalchildren for all types, the 2nd column that sums utd for observations with type=class and divides it by totalchildren for type=class and the 3rd column with pctutd for nonclass, all grouped by locale and year. Any help you can give will be greatly appreciated. And it will have a last column that has the % of entities that have nonclass type: so sas counts and sums the number of entities that have nonclass type for example in locale North and divides it by the total of entities in locale North, etc... Thank you.
*Part 1--dataset; data have; input locale $ year $ grade $ totalchildren utd type $; datalines; North 2020 5th 120 119 class South 2020 5th 140 120 nonclass East 2020 5th 18 10 nonclass West 2020 5th 9 9 class North 2020 5th 11 9 class ; *Part 2--program that has no errors except it doesn't give output I want; proc report data = have out=want nowd missing completerows ; column locale year grade totalchildren utd pctutd type; define locale / group 'Locale'; define year / group; define grade / group; define totalchildren / analysis sum; define utd / analysis noprint; define pctutd / computed; compute pctutd; pctutd=utd.sum/totalchildren.sum; endcompute; define type / across 'Type'; *--summarizes ALL; rbreak before /summarize; compute before; locale= 'ALL'; year="current"; grade="5th"; endcomp; run;
Current output
Type | ||||||
---|---|---|---|---|---|---|
Locale | year | grade | totalchildren | pctutd | class | nonclass |
ALL | current | 5th | 298 | 0.8959732 | 3 | 2 |
East | 2020 | 5th | 18 | 0.5555556 | 0 | 1 |
North | 2020 | 5th | 131 | 0.9770992 | 2 | 0 |
South | 2020 | 5th | 140 | 0.8571429 | 0 | 1 |
West | 2020 | 5th | 9 | 1 | 1 | 0 |
*--part 3 - nonworking program
proc report data = have out=want nowd missing completerows ;
column locale year grade totalchildren type,pctutd
('Overall' type pctutd);
define locale / group 'Locale';
define year / group; define grade / group;
define totalchildren / analysis sum;
define utd / analysis noprint;
define pctutd / computed;
compute pctutd;
pctutd=utd.sum/totalchildren.sum;
endcompute;
define type / across 'Type';
*--summarizes ALL;
rbreak before /summarize;
compute before;
locale= 'ALL';
year="current";
grade="5th";
endcomp;
run;
Hi: Take a look at this paper: https://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf starting on page 7. You need use absolute column numbers when you want to compute a value that's UNDER an ACROSS item.
Cynthia
Hi Cynthia,
Appreciate your guidance.
I see the compute block needs to be different from what I have for pctutd for the ACROSS usage.
I tried using the following (not sure which column SAS sees utd as since I don't have it listed in the column statement
compute pctutd;
pctutd=c5.sum/c4.sum;
endcompute;
and I'm now I"m getting the following error message:
ERROR: The variable type of C5.SUM is invalid in this context.
ERROR: The variable type of C4.SUM is invalid in this context.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: