BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anweinbe
Quartz | Level 8

Good evening SAS community.

 

I am very new to SAS and would love some help on developing some code. I'm sure this might be very simple for anyone with experience and I thank everyone in advance for sharing the knowledge.

 

I have a file that is broken out by company, year, country, product code and total sales. I created a very simple dummy file of what my real data looks like below. In short, I am trying to summarize the file so I get output for each company by year that shows me the total total sales that were in the US by company and that were outside of the US by company.

 

I would love the output to look like something like this:

 

CompanyYearDomestic - code1Domestic - code2Domestic - Code 3Foreign - Code 1Foreign - Code 2Foreign - Code 3
amazon2003405339438343839492838283292

 

 

Here is what my data looks like. I included it in excel too in case that is more helpful!

CompanyYearCountryCodeTotal
Amazon2004USA1142
Amazon2003USA2172
Amazon2004USA2178
Amazon2006USA1158
Amazon2003USA3177
Amazon2005Argentina4146
Amazon2004Cuba3182
Amazon2005England2188
Amazon2006France1110
Amazon2005Canada4176
Amazon2005Mexico3113
Sony2003USA2184
Sony2003USA1148
Sony2003USA3177
Sony2005USA2178
Sony2006USA1184
Sony2005Argentina2122
Sony2006Cuba4129
Sony2006England2109
Sony2003France3103
Sony2004Canada3158
Sony2005Mexico1187
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Hello @anweinbe and @Astounding and everyone else who might be reading along

 

There is another thread on this exact topic at 

https://communities.sas.com/t5/SAS-Programming/Summarization-Help/td-p/591335

 

Let's discuss it in one thread; not this one, but the other one.

--
Paige Miller

View solution in original post

4 REPLIES 4
Astounding
PROC Star
It's easier if you first create a variable to categorize foreign versus domestic:

data want;
set have;
if country='USA' then category='Domestic';
else category = 'Foreign';
run;

Next, summarize the data:

proc summary data=want nway;
var total;
class category company year code;
output out=summarized sum=;
run;

Examine the results and see if you still want to reformat the numbers.
anweinbe
Quartz | Level 8

I think I'm missing something obvious. Perhaps I'm not specifying my table correctly in the "data want;" part?

 

Here is my complete code:
 

PROC IMPORT DATAFILE="/home/creighton/anweinb1/Pensions/ExcelTest1.xlsx"
OUT=WORK.Test_Data1
DBMS=XLSX
REPLACE;
RUN;

PROC PRINT WORK.Test_Data1; RUN;

 

data want;
set have;
if country='USA' then category='Domestic';
else category = 'Foreign';
run;

 

proc summary data=want nway;
var total;
class category company year code;
output out=summarized sum=;
run;

Astounding
PROC Star

You need to use the actual name(s) of your data sets.

 

In the same code I posted, "have" is just the name we typically assume will be the data that you have already.  Since you imported the data and called it Test_Data1, you need to change the SET statement accordingly:

set Test_Data1;

PaigeMiller
Diamond | Level 26

Hello @anweinbe and @Astounding and everyone else who might be reading along

 

There is another thread on this exact topic at 

https://communities.sas.com/t5/SAS-Programming/Summarization-Help/td-p/591335

 

Let's discuss it in one thread; not this one, but the other one.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 812 views
  • 2 likes
  • 3 in conversation