across_Hi,
I'm looking for an equivelant to Excel's COUNTIF function in SAS EG Advanced Expression Editor. Below is an example of what I'd like to achieve
INPUT DATASET
| name | age |
| bill | 14 |
| bob | 18 |
| ben | 21 |
| sarach | 18 |
| shane | 14 |
| sonya | 15 |
OUTPUT DATASET
| name | age | count of age |
| bill | 14 | 2 |
| bob | 18 | 2 |
| ben | 21 | 1 |
| sarach | 18 | 2 |
| shane | 14 | 2 |
| sonya | 15 | 1 |
I have looked at other sas forum entries but can't quite figure them out. I understand that advanced expression editor may be limited to calculating based on the row only, but am not sure. If someone could please how I can attain this in SAS EG I would be most appreciative.
Regards
Assuming you wanted to use query builder then try the following:
1. Add Name, Age
2. Add Computed Column, Summarized Column, Add Age, Count-> make sure to name the column appropriately
3. Under summary groups, De select Automatically select and manually select only Age.
If you want code:
proc sql;
create table want as
select name, age, count(age) as count_age
from sashelp.class
group by age;
quit;
Assuming you wanted to use query builder then try the following:
1. Add Name, Age
2. Add Computed Column, Summarized Column, Add Age, Count-> make sure to name the column appropriately
3. Under summary groups, De select Automatically select and manually select only Age.
If you want code:
proc sql;
create table want as
select name, age, count(age) as count_age
from sashelp.class
group by age;
quit;
Thank you so much Reeza
😄
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!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.