Is it possible to aggregate a column and put the aggregated numbers into an existing table in SAS Prepare Data? What codes should I look at?
Yes it's possible. Please show an example of what you're trying to do and more details so we can help provide an appropriate solution.
For example, are you adding a new column? New rows? Does it need to have specific names?
Also, are you using SAS Studio with the Tasks or coding with data steps?
@ZoeZoe wrote:
Is it possible to aggregate a column and put the aggregated numbers into an existing table in SAS Prepare Data? What codes should I look at?
Hi,
Thanks for your reply. I have a table named “Test” in Prepare Data in SAS data studio. My Table looks like this:
Test
Sequence | Province | ER_Code | NOC_Code | Number of jobs |
2019m1 | QC | Capitale-Nationale | 0011 | 1 |
2019m1 | QC | Chaudi�re-Appalaches | 0011 | 1 |
2019m1 | QC | Montr�al | 0011 | 1 |
2019m1 | NL | Avalon Peninsula | 0012 | 3 |
2019m1 | NL | West Coast--Northern Peninsula--Labrador | 0012 | 3 |
2019m1 | PE | Prince Edward Island | 0012 | 2 |
2019m1 | NS | Halifax | 0012 | 9 |
2019m2 | QC | Capitale-Nationale | 0011 | 2 |
2019m2 | QC | Chaudi�re-Appalaches | 0011 | 3 |
2019m2 | QC | Montr�al | 0011 | 4 |
2019m2 | NL | Avalon Peninsula | 0012 | 3 |
2019m2 | NL | West Coast--Northern Peninsula--Labrador | 0012 | 3 |
2019m2 | PE | Prince Edward Island | 0012 | 2 |
2019m2 | NS | Halifax | 0012 | 9 |
I want the number of jobs aggregated by sequence & NOC-Code; and sequence & NOC-Code & province and add two new columns to my existing table “Test” as this:
Test
Sequence | Province | ER_Code | NOC_Code | Number of jobs | Aggregated by sequence & NOC-Code | Aggregated by sequence & NOC-Code & province |
2019m1 | QC | Capitale-Nationale | 0011 | 1 | 3 | 3 |
2019m1 | QC | Chaudi�re-Appalaches | 0011 | 1 | 3 | 3 |
2019m1 | QC | Montr�al | 0011 | 1 | 3 | 3 |
2019m1 | NL | Avalon Peninsula | 0012 | 3 | 17 | 6 |
2019m1 | NL | West Coast--Northern Peninsula--Labrador | 0012 | 3 | 17 | 6 |
2019m1 | PE | Prince Edward Island | 0012 | 2 | 17 | 2 |
2019m1 | NS | Halifax | 0012 | 9 | 17 | 9 |
2019m2 | QC | Capitale-Nationale | 0011 | 1 | 9 | 9 |
2019m2 | QC | Chaudi�re-Appalaches | 0011 | 1 | 9 | 9 |
2019m2 | QC | Montr�al | 0011 | 1 | 9 | 9 |
2019m2 | NL | Avalon Peninsula | 0012 | 3 | 17 | 6 |
2019m2 | NL | West Coast--Northern Peninsula--Labrador | 0012 | 3 | 17 | 6 |
2019m2 | PE | Prince Edward Island | 0012 | 2 | 17 | 2 |
2019m2 | NS | Halifax | 0012 | 9 | 17 | 9 |
Also, I want to use the Code/ Data steps to add the two other columns to my existing table
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.