<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Proc means summary of &amp;quot;duplicate&amp;quot; values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74386#M21574</link>
    <description>That's great!&lt;BR /&gt;
Yes, that is what I was looking for. (I must confess that my sas skills are rather limited!)&lt;BR /&gt;
I would like to have my date on date7. format I know the long way already  (by separating the year and the quarter and then joining then back) , how could I accomplish that in a short way?&lt;BR /&gt;
Thank you very much.</description>
    <pubDate>Mon, 23 Feb 2009 12:18:17 GMT</pubDate>
    <dc:creator>coba</dc:creator>
    <dc:date>2009-02-23T12:18:17Z</dc:date>
    <item>
      <title>Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74376#M21564</link>
      <description>I have data (excel file) per country, per product, per month and the quantity. However, I would like to  summarize the data per quarter in SAS. &lt;BR /&gt;
&lt;BR /&gt;
The problem I am having is that if for a country the same quantity is given twice (within the quarter) then PROC MEANS only take one of the two quantities. So I am missing data. &lt;BR /&gt;
Is there a way to fix this problem with a SAS procedure?&lt;BR /&gt;
Thank you in advance for your SAS help&lt;BR /&gt;
coba</description>
      <pubDate>Tue, 17 Feb 2009 15:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74376#M21564</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-17T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74377#M21565</link>
      <description>The problem is elsewhere in your program.  MEANS uses all the data it gets.  If the variable in the VAR statement has a missing value, then it does not count toward the mean or other statistics (except N and NMISS).&lt;BR /&gt;
&lt;BR /&gt;
If you are losing duplicates somewhere, it is often in a FIRST. or LAST. construct in the DATA step or in the DISTINCT option of SQL.  Without more information from you (code, log, lst), I'm at a loss to help further.</description>
      <pubDate>Tue, 17 Feb 2009 15:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74377#M21565</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2009-02-17T15:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74378#M21566</link>
      <description>Probably I am doing something wrong. Before I use the proc means I put my data and quarters (if month in (1,2,3) then qtr=1, etc... Then I summarize them. Should I think of another way to sum my quantities?&lt;BR /&gt;
Thanks for your help.</description>
      <pubDate>Tue, 17 Feb 2009 16:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74378#M21566</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-17T16:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74379#M21567</link>
      <description>As Doc said ... unless we see your code, there really isn't a way for us to help figure out why you are having this problem (if you are having a problem at all).</description>
      <pubDate>Tue, 17 Feb 2009 16:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74379#M21567</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2009-02-17T16:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74380#M21568</link>
      <description>I have something like this:&lt;BR /&gt;
&lt;BR /&gt;
data work.test1;&lt;BR /&gt;
set work.test;&lt;BR /&gt;
	if Month in (1,2,3) then m=1;&lt;BR /&gt;
	else if Month in (4,5,6) then m=4; &lt;BR /&gt;
	else if Month in (7,8,9) then m=7; &lt;BR /&gt;
	else if Month in (10,11,12) then m=10;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data work.test2;&lt;BR /&gt;
set work.test1;&lt;BR /&gt;
	format date date7.;&lt;BR /&gt;
		date=mdy(m,01,year);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means nway data=work.test2 missing noprint;&lt;BR /&gt;
class country date product code ;&lt;BR /&gt;
var quantity;&lt;BR /&gt;
	output out=work.test3 (drop=_TYPE_ _FREQ_) sum=quantity;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 Feb 2009 16:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74380#M21568</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-17T16:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74381#M21569</link>
      <description>I don't see anything in your code that could cause the problem that you spoke of originally: "The problem I am having is that if for a country the same quantity is given twice (within the quarter) then PROC MEANS only take one of the two quantities."&lt;BR /&gt;
&lt;BR /&gt;
Your code is not causing missing values to appear in the data. So it must be something in the data. Could you post some sample data?&lt;BR /&gt;
&lt;BR /&gt;
By the way, there is no need for data set test2. It accomplishes little, and could be combined into data set test1.&lt;BR /&gt;
&lt;BR /&gt;
data work.test1;&lt;BR /&gt;
set work.test;&lt;BR /&gt;
if Month in (1,2,3) then m=1;&lt;BR /&gt;
else if Month in (4,5,6) then m=4;&lt;BR /&gt;
else if Month in (7,8,9) then m=7;&lt;BR /&gt;
else if Month in (10,11,12) then m=10;&lt;BR /&gt;
date=mdy(m,01,year);&lt;BR /&gt;
format date date7.;&lt;BR /&gt;
drop m;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 Feb 2009 17:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74381#M21569</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2009-02-17T17:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74382#M21570</link>
      <description>if taking out steps might remove the problem, try doing the analysis without any of these extra steps that only provide a date at the start of a quarter. PROC MEANS will summarise by quarters, just by providing a suitable format for that class variable[pre]   proc means nway data= original missing noprint;&lt;BR /&gt;
       var    quantity ;&lt;BR /&gt;
       class  country month product code ;&lt;BR /&gt;
       format         month yyQ. ;  &lt;BR /&gt;
       output out=work.test3( drop= _TYPE_ _FREQ_ ) sum= ;&lt;BR /&gt;
   run ;[/pre]  I prefer the yyQ. format but you may prefer alternatives like YYQR and YYQx (with C,D,N,P or S for that x) or QTR without the year, or more exotically, construct your own format, with PROC FORMAT PICTURE...&lt;BR /&gt;
&lt;BR /&gt;
but I see no reason why proc means would not include all obs it reads (unless your analysis variable QUANTITY is missing). Maybe you should keep _freq_ to check the number of obs in each class group add up to the grand total you expect.&lt;BR /&gt;
&lt;BR /&gt;
If you must have the values of day, month, year on exactly the start of a quarter, perform that process on the summarised data. It will be quicker because there is less data. A simplistic assignment to transform the month to quarter start date[pre]      q_start_date = intnx( 'qtr', month,0 ) ;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
good luck&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 17 Feb 2009 20:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74382#M21570</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-17T20:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74383#M21571</link>
      <description>I do not know what I am doing wrong but the result is for m=1960Q1 for all observations.&lt;BR /&gt;
&lt;BR /&gt;
I already checked if year and month are numeric values, they are!&lt;BR /&gt;
I put together this:&lt;BR /&gt;
&lt;BR /&gt;
data test1;&lt;BR /&gt;
input  Product $ country  $ year month quantity;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10010000	Brazil	2007	1	100&lt;BR /&gt;
10010000	Brazil	2007	1	23&lt;BR /&gt;
10010000	Brazil	2007	3	100&lt;BR /&gt;
10010000	Brazil	2007	3	360&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc means nway data= work.test1 missing noprint;&lt;BR /&gt;
var    quantity ;       &lt;BR /&gt;
class  country product year month;       &lt;BR /&gt;
format month YYQ. ;    /* with C,D,N,P or S for that x */     &lt;BR /&gt;
output out=work.test2( drop= _TYPE_ _FREQ_ ) sum= ;   &lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
but the result is not what I expect.</description>
      <pubDate>Mon, 23 Feb 2009 10:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74383#M21571</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-23T10:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74384#M21572</link>
      <description>Numbers with values in the range from 1 to 12 (month variable) will format only as 1960Q1 with YYQ. format.&lt;BR /&gt;
The YYQ format is suitable for a numeric variable which contains a number of days since the beginning of 1960 (a standard SAS date). &lt;BR /&gt;
I think this standard simplifies data analyses involving dates because a date becomes only one variable and many processes and formats can be (and have been) created to "work with dates". &lt;BR /&gt;
Unfortunately you have one variable for year and a separate variable for month, which makes your analyses complicated. Easily, you can create a single standard SAS date from these two, with :[pre]      anDate = mdy( month,1,year) ;[/pre]That provides a class variable which is suitable for formatting with YYQ.&lt;BR /&gt;
The anDate class variable replaces month and year.&lt;BR /&gt;
With some extra data lines to demonstrate more than one output line, here is some alternative code[pre]data test1;&lt;BR /&gt;
   input Product $ country $ year month quantity;&lt;BR /&gt;
   anDate = mdy( month,1,year) ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10010000 Brazil 2007 1 100&lt;BR /&gt;
10010000 Brazil 2007 1 23&lt;BR /&gt;
10010000 Brazil 2007 3 100&lt;BR /&gt;
10010000 Brazil 2007 4 360&lt;BR /&gt;
10010000 Brazil 2007 6 360&lt;BR /&gt;
10010000 Brazil 2007 10 360&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc means nway data= work.test1 missing noprint;&lt;BR /&gt;
   var    quantity ; &lt;BR /&gt;
   class  country product anDate; &lt;BR /&gt;
   format anDate YYQ. ;&lt;BR /&gt;
   output out=work.test2 sum= ; &lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
My results from a PROC PRINT like: [pre]ods listing ;&lt;BR /&gt;
title YYQ 'demo';&lt;BR /&gt;
option nodate nonumber ls=70 nocenter ;&lt;BR /&gt;
proc print ;&lt;BR /&gt;
 id country product anDate;&lt;BR /&gt;
 var quantity _freq_ ;&lt;BR /&gt;
 sum quantity _freq_ ;&lt;BR /&gt;
 format anDate YYQ. ; &lt;BR /&gt;
run;[/pre]follow[pre]YYQ demo&lt;BR /&gt;
&lt;BR /&gt;
country    Product     anDate    quantity    _FREQ_&lt;BR /&gt;
&lt;BR /&gt;
Brazil     10010000    2007Q1       223         3&lt;BR /&gt;
Brazil     10010000    2007Q2       720         2&lt;BR /&gt;
Brazil     10010000    2007Q4       360         1&lt;BR /&gt;
                                 ========    ======&lt;BR /&gt;
                                   1303         6[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 23 Feb 2009 11:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74384#M21572</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-02-23T11:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74385#M21573</link>
      <description>coba,&lt;BR /&gt;
&lt;BR /&gt;
You are formatting a month number (1, 2, etc) using a format designed for serial dates. Serial date 1 is 1st or 2nd Jan 1960, and 3 is 3rd or 4th Jan 1960, both of these are in Q1 of 1960, so SAS is doing what you ask - it doesn't know to join up the year and month variables.&lt;BR /&gt;
&lt;BR /&gt;
data test1;&lt;BR /&gt;
input Product $ country $ year month quantity;&lt;BR /&gt;
/* I've added a date that is a composite of the year and month */&lt;BR /&gt;
dt = input('01'||put(month, z2.)||put(year, 4.), ddmmyy8.);&lt;BR /&gt;
/* I've added a couple of lines of data to go into the following quarter */&lt;BR /&gt;
datalines;&lt;BR /&gt;
10010000 Brazil 2007 1 100&lt;BR /&gt;
10010000 Brazil 2007 1 23&lt;BR /&gt;
10010000 Brazil 2007 3 100&lt;BR /&gt;
10010000 Brazil 2007 3 360&lt;BR /&gt;
10010000 Brazil 2007 4 100&lt;BR /&gt;
10010000 Brazil 2007 5 23&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means nway data= work.test1 missing noprint;&lt;BR /&gt;
var quantity ; &lt;BR /&gt;
/* Use the date variable in the class statement */&lt;BR /&gt;
class country product dt;&lt;BR /&gt;
/* Format the date variable */ &lt;BR /&gt;
format dt YYQ. ; /* with C,D,N,P or S for that x */ &lt;BR /&gt;
output out=work.test2( drop= _TYPE_ _FREQ_ ) sum= ; &lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
Output:&lt;BR /&gt;
&lt;BR /&gt;
Obs    country    Product       dt      quantity&lt;BR /&gt;
&lt;BR /&gt;
 1     Brazil     10010000    2007Q1       583&lt;BR /&gt;
 2     Brazil     10010000    2007Q2       123&lt;BR /&gt;
&lt;BR /&gt;
Is this what you were hoping for?&lt;BR /&gt;
&lt;BR /&gt;
ProcMe</description>
      <pubDate>Mon, 23 Feb 2009 11:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74385#M21573</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-23T11:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74386#M21574</link>
      <description>That's great!&lt;BR /&gt;
Yes, that is what I was looking for. (I must confess that my sas skills are rather limited!)&lt;BR /&gt;
I would like to have my date on date7. format I know the long way already  (by separating the year and the quarter and then joining then back) , how could I accomplish that in a short way?&lt;BR /&gt;
Thank you very much.</description>
      <pubDate>Mon, 23 Feb 2009 12:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74386#M21574</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-23T12:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means summary of "duplicate" values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74387#M21575</link>
      <description>do not worry about my date format, I managed</description>
      <pubDate>Mon, 23 Feb 2009 12:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-means-summary-of-quot-duplicate-quot-values/m-p/74387#M21575</guid>
      <dc:creator>coba</dc:creator>
      <dc:date>2009-02-23T12:33:58Z</dc:date>
    </item>
  </channel>
</rss>

