I want to display the number of project having x applications (in the dataset 1 row = 1 application, thats why I consider 1 ID_Project as 1 application) :
SELECT
(CASE
WHEN COUNT(ID_Project) = 1 THEN 'Projects with 1 application'
WHEN COUNT(ID_Project) = 2 THEN 'Projects with 2 applications'
WHEN COUNT(ID_Project) = 3 THEN 'Projects with 3 applications'
ELSE 'Projects with 3+ applications'
END), COUNT(ID_Project)
FROM TEST2
GROUP BY
(CASE
WHEN COUNT(ID_Project) = 1 THEN 'Projects with 1 application'
WHEN COUNT(ID_Project) = 2 THEN 'Projects with 2 applications'
WHEN COUNT(ID_Project) = 3 THEN 'Projects with 3 applications'
ELSE 'Projects with 3+ applications'
END); I have the following error "Summary functions are restricted to the select and having clauses only". I know that I can't use count in the group by but I think Its mandatory if I want to have categories.
Thanks for your help !
So project 1000 has 8 applications and project 5000 has 2 applications? I think using PROC FREQ twice gets you what you want.
proc format;
value custf 1='Projects with 1 application'
2='Projects with 2 applications'
3='Projects with 3 applications'
4-high='Projects with >3 applications';
run;
proc freq data=have;
tables id_project/noprint out=applications;
run;
proc freq data=applications;
tables count;
format count custf.;
run;
I want to display the number of project having x applications
PROC FREQ would be a whole lot easier.
proc format;
value custf 1='Projects with 1 application'
2='Projects with 2 applications'
3='Projects with 3 applications'
4-high='Projects with >3 applications';
run;
proc freq data=have;
tables id_project;
format id_project custf;
run;
Please show us example of your input data. Please show us the desired output.
Its a very confidential dataset but I made an exemple table that looks pretty similar with the required columns.
Table :
Output:
| Nbr Projects | |
Projects with 1 application | xx |
Projects with 2 applications | xx |
Projects with 3 applications | xx |
Projects with >3 applications | xx |
So project 1000 has 8 applications and project 5000 has 2 applications? I think using PROC FREQ twice gets you what you want.
proc format;
value custf 1='Projects with 1 application'
2='Projects with 2 applications'
3='Projects with 3 applications'
4-high='Projects with >3 applications';
run;
proc freq data=have;
tables id_project/noprint out=applications;
run;
proc freq data=applications;
tables count;
format count custf.;
run;
Good news!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.