BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Haydo
Obsidian | Level 7

I have dataset (2 Million rows) with the following varibales:

  • Suburb
  • Suburb_Latitude
  • Suburb_longitude
  • Group (Group1, Group2)
  • SubGroup(Subrgroup1, Subrgroup2,Subrgroup3,Subrgroup4,Subrgroup5,Subrgroup6)
  • Offered (Y,N)
  • Count (numerical)

For the values I have used mock entries.

The Request.

I'd like 1 line per Suburb summing the Count Variable as per the table below.

Dummy Data.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Writing a DATA step is easier than getting all of those lines to appear on the page.

data want;
  input Suburb :$10. Group1 Group2 Subrgroup1-Subrgroup6 OfferedY OfferedN;
cards;
Suburb1 3322 2282 321 987 934 865 686 1811 2800 2804
Suburb2 4468 2084 1045 1270 1047 1300 466 466 3270 3282
Suburb3 4487 889 1046 250 753 931 1896 1896 2680 2696
;

If your actual data has variables with those names then a simple proc summary will work:

proc summary data=have nway;
  class suburb;
  var Group1 Group2 Subrgroup1-Subrgroup6 OfferedY OfferedN;
  output out=want sum= ;
run;

But your written description of the source made it sound more complicated. Please share a similar data step to create a small example of the source data.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Please do not post pictures of data; supply example data in a self-contained DATA step with DATALINES.

For summations like you describe, PROC MEANS/SUMMARY is the right tool.

Haydo
Obsidian | Level 7
SuburbGroup1Group2Subrgroup1Subrgroup2Subrgroup3Subrgroup4Subrgroup5Subrgroup6Offered YOffered N
Suburb133222282321987934865686181128002804
Suburb244682084104512701047130046646632703282
Suburb3448788910462507539311896189626802696
Haydo
Obsidian | Level 7
Apologies not sure how to add, DATA step with DATALINES. I've added a table with the desired outcome and I hope this helps.
Tom
Super User Tom
Super User

Writing a DATA step is easier than getting all of those lines to appear on the page.

data want;
  input Suburb :$10. Group1 Group2 Subrgroup1-Subrgroup6 OfferedY OfferedN;
cards;
Suburb1 3322 2282 321 987 934 865 686 1811 2800 2804
Suburb2 4468 2084 1045 1270 1047 1300 466 466 3270 3282
Suburb3 4487 889 1046 250 753 931 1896 1896 2680 2696
;

If your actual data has variables with those names then a simple proc summary will work:

proc summary data=have nway;
  class suburb;
  var Group1 Group2 Subrgroup1-Subrgroup6 OfferedY OfferedN;
  output out=want sum= ;
run;

But your written description of the source made it sound more complicated. Please share a similar data step to create a small example of the source data.

Haydo
Obsidian | Level 7

 

 

 

Mock up of data

          
SuburbGroup1Group2Subrgroup1Subrgroup2Subrgroup3Subrgroup4Subrgroup5Subrgroup6Offered YOffered N
Suburb121591483209642607562446117718201823
Suburb11163799112345327303240634980981
Suburb22904135567982668184530330321262133
Suburb2156472936644536645516316311451149
Suburb3157031136688264326664664938944
Suburb329175786801634896051232123217421752

 

 

Desired Outcome

          
SuburbGroup1Group2Subrgroup1Subrgroup2Subrgroup3Subrgroup4Subrgroup5Subrgroup6Offered YOffered N
Suburb133222282321987934865686181128002804
Suburb244682084104512701047130046646632703282
Suburb3448788910462507539311896189626802696

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 309 views
  • 0 likes
  • 3 in conversation