<?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: Syntax for creating a new dataset based on codes for specific variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421391#M103660</link>
    <description>Thanks for your response. What if the number of vars are different for DX and DXCC?</description>
    <pubDate>Thu, 14 Dec 2017 21:51:15 GMT</pubDate>
    <dc:creator>Melk</dc:creator>
    <dc:date>2017-12-14T21:51:15Z</dc:date>
    <item>
      <title>Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421366#M103654</link>
      <description>&lt;P&gt;I am creating a database from another and I want to keep observations that have codes in certain variables. It will look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((4100 or 4101) in (DX1-DX25)) and (100 or 101 or 105 in (DXCC1-DXCC25))) or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((4200 or 4201) in (DX1-DX25)) and (200 or 201 or 205 in (DXCC1-DXCC25)));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the syntax correct for what I want to do? I want to make sure before I run because it is a large dataset and will take a long time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 21:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421366#M103654</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-14T21:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421376#M103655</link>
      <description>&lt;P&gt;If you want to test code simply, you can do that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (obs=100);&lt;/P&gt;
&lt;P&gt;** add whatever you want to do;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, your syntax is far from working.&amp;nbsp; This would be a reasonable approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array dx {25};&lt;/P&gt;
&lt;P&gt;array dxcc {&lt;FONT color="#ff0000"&gt;23&lt;/FONT&gt;};&lt;/P&gt;
&lt;P&gt;do k=1 to 25 until;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if dx{k} in (4100, 4101) then flag_group1=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if dx{k} in (4200, 4201) then flag_group2=1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;if flag_group1=1 then do k=1 to 23 until (flag=1);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; if dxcc{k} in (100, 101, 105) then flag=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;if flag_group2=1 and flag ne 1 then do k=1 to 23 until (flag=1);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; if dxcc{k} in (200, 201, 205) then flag=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;if flag=1;&lt;/P&gt;
&lt;P&gt;drop k flag flag_group1 flag_group2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And do test it using OBS= before running against the entire data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;***** EDITED:&amp;nbsp; changes added to allow for different number of elements in each array.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Also Edited to match your AND / OR logic.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 22:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421376#M103655</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-14T22:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421382#M103656</link>
      <description>my dxcc actually has a difference length, I just noticed. Will this still work if I use the longest length of the 2 in my k-1 to x?</description>
      <pubDate>Thu, 14 Dec 2017 21:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421382#M103656</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-14T21:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421386#M103657</link>
      <description>&lt;P&gt;I'm not sure what you are asking.&amp;nbsp; Do you have some other number of elements (not 25)?&amp;nbsp; Are you talking about the lengths of character variables (which requires a slightly different syntax)?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 21:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421386#M103657</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-14T21:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421388#M103658</link>
      <description>Ah sorry - yes the number if elements in the arrays are different for DX and DXCC.</description>
      <pubDate>Thu, 14 Dec 2017 21:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421388#M103658</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-14T21:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421389#M103659</link>
      <description>&lt;P&gt;I think this code will work, with the assumption you have equal number of variables both for DX and&amp;nbsp;&lt;SPAN&gt;DXCC.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new (drop = i);&lt;BR /&gt;set old;&lt;BR /&gt;array DX{*} DX1-DX25;&lt;BR /&gt;array DXCC{*} DXCC1-DXCC25;&lt;BR /&gt;&lt;BR /&gt;do i = 1 to dim(DX);&lt;BR /&gt;&lt;BR /&gt;if DX[i] in (4100, 4101) then dx1 = 1;&lt;BR /&gt;if DXCC[i] in (100,101,105) then dxcc1=1;&lt;BR /&gt;if DX[i] in (4200, 4201) then dx2 = 1;&lt;BR /&gt;if DXCC[i] in (200,201,205) then dxcc2=1;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;if sum(dx1,dxcc1) = 2 or sum(dx2,dxcc2) = 2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 21:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421389#M103659</guid>
      <dc:creator>skyvalley81</dc:creator>
      <dc:date>2017-12-14T21:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421391#M103660</link>
      <description>Thanks for your response. What if the number of vars are different for DX and DXCC?</description>
      <pubDate>Thu, 14 Dec 2017 21:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421391#M103660</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-14T21:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for creating a new dataset based on codes for specific variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421392#M103661</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Just create 2 do loops. Something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data new (drop = i);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set old;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;array DX{*} DX1-DX25;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;array DXCC{*} DXCC1-DXCC14;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;do i = 1 to dim(DX);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if DX[i] in (4100, 4101) then dx1 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if DX[i] in (4200, 4201) then dx2 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;do i = 1 to dim(DXCC);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if DXCC[i] in (100,101,105) then dxcc1=1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if DXCC[i] in (200,201,205) then dxcc2=1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;if sum(dx1,dxcc1) = 2 or sum(dx2,dxcc2) = 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would suggest to test your code first on a small subset &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 21:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-for-creating-a-new-dataset-based-on-codes-for-specific/m-p/421392#M103661</guid>
      <dc:creator>skyvalley81</dc:creator>
      <dc:date>2017-12-14T21:55:57Z</dc:date>
    </item>
  </channel>
</rss>

