<?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: How do i convert this ms access sql query to a sas query? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385699#M92297</link>
    <description>&lt;P&gt;You should be able to do that with PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;So you have three types of variables in that query. Grouping variables, Sums and "Firsts".&lt;/P&gt;
&lt;P&gt;So here is a simple example using PROC SUMMARY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input group $ group_code amount ;
cards;
A 1 10
A 1 10
A 2 10
B 3 5
B 3 5
;

%let group= group;
%let sum= amount;
%let first=group_code;
proc summary nway data=have  ;
  class &amp;amp;group ;
  var &amp;amp;sum ;
  output out=want(drop=_type_ _freq_)
    idgroup( out[1] (&amp;amp;first) = ) 
    sum=
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                group_
Obs    group     code     amount

 1       A         1        30
 2       B         3        10&lt;/PRE&gt;
&lt;P&gt;So basically for this to work for your data you need to supply the space delimited liss of variable names into the macro variables and point to the source table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let group= CUSTOMER_NUMBER CUSTOMER_NAME ZIP5_CODE ....;
%let sum=YTDPYNET_QTY YTDPYNET_SALES ...;
%let first=SALES_DISTRICT_CODE SALES_DISTRICT_DESC ....;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I am not sure if you need to add a FORMAT statement to handle the values of&amp;nbsp;STPWeightedGrwth or if you will first need to round it to replicate how Access is handleing that FORMAT() function call.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Aug 2017 16:22:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-08-04T16:22:58Z</dc:date>
    <item>
      <title>How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385678#M92288</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone explain what the "First." functions in MS ACCESS&amp;nbsp;are doing here and how can&amp;nbsp;I convert this to a SAS query?&lt;/P&gt;&lt;P&gt;is it just reomving duplicate data?&amp;nbsp; I'm not well versed in ms access.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help you can provide!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT [2h CustPVM &amp;gt;109000].CUSTOMER_NUMBER, 
[2h CustPVM &amp;gt;109000].CUSTOMER_NAME, 
[2h CustPVM &amp;gt;109000].ZIP5_CODE,
 [2h CustPVM &amp;gt;109000].CITY,
 [2h CustPVM &amp;gt;109000].STATE, 
[2h CustPVM &amp;gt;109000].CBSA,
 First([2h CustPVM &amp;gt;109000].SALES_DISTRICT_CODE) AS SALES_DISTRICT_CODE, 
First([2h CustPVM &amp;gt;109000].SALES_DISTRICT_DESC) AS SALES_DISTRICT_DESC,
 First([2h CustPVM &amp;gt;109000].SALES_GROUP_CODE) AS SALES_GROUP_CODE, 
First([2h CustPVM &amp;gt;109000].SALES_GROUP_DESC) AS SALES_GROUP_DESC, 
[2h CustPVM &amp;gt;109000].CUSTOMER_GROUP1, 
[2h CustPVM &amp;gt;109000].CUSTOMER_GROUP1_DESC, 
[2h CustPVM &amp;gt;109000].IDN, [2h CustPVM &amp;gt;109000].CUSTOMER_GROUP2, 
[2h CustPVM &amp;gt;109000].CUSTOMER_GROUP2_DESC, 
[2h CustPVM &amp;gt;109000].[GPO Name],
[2h CustPVM &amp;gt;109000].F400, 
[2h CustPVM &amp;gt;109000].MATERIAL_NUMBER, 
[2h CustPVM &amp;gt;109000].MATERIAL_DESC,
[2h CustPVM &amp;gt;109000].LEVEL5_DESC_CATEGORY,
[2h CustPVM &amp;gt;109000].LEVEL4_DESC_CLASS, 
[2h CustPVM &amp;gt;109000].BUSLINE,
[2h CustPVM &amp;gt;109000].BUSLINE_DESC, 
[2h CustPVM &amp;gt;109000].BUSLINE_GROUPING_3, 
[2h CustPVM &amp;gt;109000].BUSLINE_GROUPING_2, 
[2h CustPVM &amp;gt;109000].BUSLINE_GROUPING, 
[2h CustPVM &amp;gt;109000].ORTHO_DIVISION, 
[2h CustPVM &amp;gt;109000].ALT_LEVEL1_DESC, 
[2h CustPVM &amp;gt;109000].ALT_LEVEL2_DESC, 
First([2h CustPVM &amp;gt;109000].PROMO) AS PROMO, 
First([2h CustPVM &amp;gt;109000].[Promo Description]) AS [Promo Description], 
First([2h CustPVM &amp;gt;109000].[Pricing Type]) AS [Pricing Type], 
Sum([2h CustPVM &amp;gt;109000].YTDPYNET_QTY) AS YTDPYNET_QTY, 
Sum([2h CustPVM &amp;gt;109000].YTDPYNET_SALES) AS YTDPYNET_SALES, 
Sum([2h CustPVM &amp;gt;109000].YTDPYGROSS_SALES) AS YTDPYGROSS_SALES, 
Sum([2h CustPVM &amp;gt;109000].YTDPYCOST_OF_SALES) AS YTDPYCOST_OF_SALES, 
Sum([2h CustPVM &amp;gt;109000].YTDCYNET_QTY) AS YTDCYNET_QTY, 
Sum([2h CustPVM &amp;gt;109000].YTDCYNET_SALES) AS YTDCYNET_SALES, 
Sum([2h CustPVM &amp;gt;109000].YTDCYGROSS_SALES) AS YTDCYGROSS_SALES, 
Sum([2h CustPVM &amp;gt;109000].YTDCYCOST_OF_SALES) AS YTDCYCOST_OF_SALES, 
Format([STPWeightedGrwth],"0.00000%") AS STPWeightedGrwthString


FROM [2h CustPVM &amp;gt;109000]


GROUP BY [2h CustPVM &amp;gt;109000].CUSTOMER_NUMBER,       [2h CustPVM &amp;gt;109000].CUSTOMER_NAME,      [2h CustPVM &amp;gt;109000].ZIP5_CODE,     [2h CustPVM &amp;gt;109000].CITY,      [2h CustPVM &amp;gt;109000].STATE,     [2h CustPVM &amp;gt;109000].CBSA, 
[2h CustPVM &amp;gt;109000].CUSTOMER_GROUP1,       [2h CustPVM &amp;gt;109000].CUSTOMER_GROUP1_DESC,      [2h CustPVM &amp;gt;109000].IDN,      [2h CustPVM &amp;gt;109000].CUSTOMER_GROUP2,      [2h CustPVM &amp;gt;109000].CUSTOMER_GROUP2_DESC,    
[2h CustPVM &amp;gt;109000].[GPO Name],      [2h CustPVM &amp;gt;109000].F400,      [2h CustPVM &amp;gt;109000].MATERIAL_NUMBER,      [2h CustPVM &amp;gt;109000].MATERIAL_DESC,     [2h CustPVM &amp;gt;109000].LEVEL5_DESC_CATEGORY, 
[2h CustPVM &amp;gt;109000].LEVEL4_DESC_CLASS,     [2h CustPVM &amp;gt;109000].BUSLINE,      [2h CustPVM &amp;gt;109000].BUSLINE_DESC,      [2h CustPVM &amp;gt;109000].BUSLINE_GROUPING_3,      [2h CustPVM &amp;gt;109000].BUSLINE_GROUPING_2,     
[2h CustPVM &amp;gt;109000].BUSLINE_GROUPING,     [2h CustPVM &amp;gt;109000].ORTHO_DIVISION,     [2h CustPVM &amp;gt;109000].ALT_LEVEL1_DESC,     [2h CustPVM &amp;gt;109000].ALT_LEVEL2_DESC,    Format([STPWeightedGrwth],"0.00000%");&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 15:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385678#M92288</guid>
      <dc:creator>joseatmc</dc:creator>
      <dc:date>2017-08-04T15:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385689#M92291</link>
      <description>&lt;P&gt;I am not very sure, but from what I have read it, it implies first record as enetered in MS access. Personally I feel this is tough to emulate.&amp;nbsp;for example , say there are multiple values of sales_distict_code&amp;nbsp; and&amp;nbsp; they are 123, 421, 223. The first functions picks up the first value entered in MS access and this could be anything as it depends on entry of that value in MS access. A min or max function will help you achieve similar results by picking one value but might not be same result as&amp;nbsp; in MS Access. I would try to use min or max function instead of first and then compare the results. Probably you may need to contact business user and ask, what is that he wants to see in output.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 15:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385689#M92291</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-08-04T15:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385695#M92294</link>
      <description>&lt;P&gt;Thanks for that, however, some of the fields are character for example&amp;nbsp; Sales_district_desc, and Sales_Group_desc, and Promo_desc and Pricing_type are all character fields... Sales_district_code is a number, as well as Sales group_code, and Promo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how will min and max work with character fields?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385695#M92294</guid>
      <dc:creator>joseatmc</dc:creator>
      <dc:date>2017-08-04T16:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385699#M92297</link>
      <description>&lt;P&gt;You should be able to do that with PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;So you have three types of variables in that query. Grouping variables, Sums and "Firsts".&lt;/P&gt;
&lt;P&gt;So here is a simple example using PROC SUMMARY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input group $ group_code amount ;
cards;
A 1 10
A 1 10
A 2 10
B 3 5
B 3 5
;

%let group= group;
%let sum= amount;
%let first=group_code;
proc summary nway data=have  ;
  class &amp;amp;group ;
  var &amp;amp;sum ;
  output out=want(drop=_type_ _freq_)
    idgroup( out[1] (&amp;amp;first) = ) 
    sum=
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                group_
Obs    group     code     amount

 1       A         1        30
 2       B         3        10&lt;/PRE&gt;
&lt;P&gt;So basically for this to work for your data you need to supply the space delimited liss of variable names into the macro variables and point to the source table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let group= CUSTOMER_NUMBER CUSTOMER_NAME ZIP5_CODE ....;
%let sum=YTDPYNET_QTY YTDPYNET_SALES ...;
%let first=SALES_DISTRICT_CODE SALES_DISTRICT_DESC ....;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I am not sure if you need to add a FORMAT statement to handle the values of&amp;nbsp;STPWeightedGrwth or if you will first need to round it to replicate how Access is handleing that FORMAT() function call.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385699#M92297</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-04T16:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385702#M92299</link>
      <description>When I changed my query from first to min I got the exact out put as in the Access database. not sure if min can replace first in every scenario , but it did in this one. Thank you!!&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385702#M92299</guid>
      <dc:creator>joseatmc</dc:creator>
      <dc:date>2017-08-04T16:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do i convert this ms access sql query to a sas query?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385703#M92300</link>
      <description>&lt;P&gt;From the net:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/bb177902(v=office.12).aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/bb177902(v=office.12).aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;Because records are usually returned in no particular order (unless the query includes an&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/bb208913(v=office.12).aspx" target="_blank"&gt;ORDER BY&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;clause), the records returned by these functions will be arbitrary."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So the query you present might work if all the values within the group by are the same, otherwise it is just picking the first one from a random order. &amp;nbsp;Pull the data out as is from the access database, assign a numer to each record to show how it is in the access db, then use that number in your query.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or better yet, find out what the&amp;nbsp;&lt;STRONG&gt;intention&lt;/STRONG&gt; of the query was, and build it specifically in SAS in a logical and repeatable manner. &amp;nbsp;For instance that vast amount of code you present could be replaced by one proc means, by group being the group by variables.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-convert-this-ms-access-sql-query-to-a-sas-query/m-p/385703#M92300</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-04T16:26:36Z</dc:date>
    </item>
  </channel>
</rss>

