<?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 SQL help on transpose logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930685#M366158</link>
    <description>&lt;P&gt;I've attached the source and target and below are the rules to derive the target,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Based on ID order the DIAG Codes by line number&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Populate only Distinct DI codes in above order.&lt;/P&gt;
&lt;P&gt;3) Assign the LI_SEQ based on the order of distinct Di Codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to use proc transpose and I need help in writing SQL or it would nice if you point to the document which can help here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ignore the data inside table as I shown only few data in source and target to help understand the logic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Source Table&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source" style="width: 743px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96959i4C5FA7F52C681D50/image-size/large?v=v2&amp;amp;px=999" role="button" title="Source.PNG" alt="Source" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Source&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Target:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Target" style="width: 415px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96960i8640AC1327704E0C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Target.PNG" alt="Target" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Target&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2024 18:49:34 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2024-06-03T18:49:34Z</dc:date>
    <item>
      <title>SQL help on transpose logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930685#M366158</link>
      <description>&lt;P&gt;I've attached the source and target and below are the rules to derive the target,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Based on ID order the DIAG Codes by line number&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Populate only Distinct DI codes in above order.&lt;/P&gt;
&lt;P&gt;3) Assign the LI_SEQ based on the order of distinct Di Codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to use proc transpose and I need help in writing SQL or it would nice if you point to the document which can help here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ignore the data inside table as I shown only few data in source and target to help understand the logic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Source Table&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source" style="width: 743px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96959i4C5FA7F52C681D50/image-size/large?v=v2&amp;amp;px=999" role="button" title="Source.PNG" alt="Source" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Source&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Target:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Target" style="width: 415px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96960i8640AC1327704E0C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Target.PNG" alt="Target" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Target&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 18:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930685#M366158</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2024-06-03T18:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: SQL help on transpose logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930701#M366161</link>
      <description>&lt;P&gt;What is a Diag code? I don't see anything by that name.&lt;/P&gt;
&lt;P&gt;What "above order"? Especially if it relates to character values like A542. Because "order" to&amp;nbsp; you may not be apparent to anything else. With normal rules for character values "A9" is after "A542". So a very clear definition of what "order" is to be applied is critical. So rethink and re-describe the rules so we can have a change of providing an answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is that "target" the exact solution for the shown source? It feels like that target may be missing more than a few rows. If you do not provide a complete target then you may have to provide more rules about why something gets left out of the target.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see any rules about use of any of the pointer variables or how such a value ends up in the target set.&lt;/P&gt;
&lt;P&gt;And there is nothing at all about how HDR_POSITION is to be created or assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you have been shown more than once how to provide data as a data step. Please provide data in such form so we don't have to guess about actual variable names or types.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 19:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930701#M366161</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-03T19:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL help on transpose logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930716#M366165</link>
      <description>&lt;P&gt;I don't think you can really do a transpose in SQL. You probably need to abandon that requirement.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 20:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930716#M366165</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-03T20:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: SQL help on transpose logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930718#M366167</link>
      <description>&lt;P&gt;Why SQL?&amp;nbsp; I would assume that would just make the problem much more complicated than it appears to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Photographs of data are impossible to code with.&amp;nbsp; And photographs of dataset that use different variable names than the ones used in the problem description make it even harder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like you have two groups of variables with numeric suffixes.&amp;nbsp; Is it safe to assume they are related to each other so that the first entry in the first group is paired with the first entry in the second group?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see any LINE NUMBER variable in your dataset.&amp;nbsp; I thought perhaps you meant LI_SEQ, but then you say you want to create that variable.&amp;nbsp; But if you want to create it then why is it already in the SOURCE dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do have&amp;nbsp; a DATE variable that appears to be named PAID_DATE.&amp;nbsp; Do you want to order the data by PAID_DATE?&amp;nbsp; Not sure if that makes much sense unless your analysis is about the economic impact of delaying payments?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean to say that even though there is no variable by which to order the data you want to process it in the order it appears?&amp;nbsp; That is not something the SQL can do.&amp;nbsp; But it is trivial in SAS code.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 20:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930718#M366167</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-03T20:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL help on transpose logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930748#M366177</link>
      <description>&lt;P&gt;SQL is not very suitable for transposing data. Using SAS Proc Transpose or a data step is what you should be using.&lt;/P&gt;
&lt;P&gt;The only reason for a SQL would be if processing needs to get pushed to a database. If so then you would need to consult the documentation for the database and use explicit database specific SQL if and as available (like the PIVOT command in Oracle).&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 23:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-help-on-transpose-logic/m-p/930748#M366177</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-06-03T23:40:42Z</dc:date>
    </item>
  </channel>
</rss>

