<?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: Extraction of data using select () when or if then. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663817#M198238</link>
    <description>&lt;P&gt;There are two issues in your code&lt;/P&gt;
&lt;P&gt;1) I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt; , one reason is you need to use " " to resolve the macro variable and used to subset&lt;/P&gt;
&lt;P&gt;2) Also the important thing i noticed is that though your second code is correct, it did not work and the reason is because that the macro variables resolved to YES, NO and TOTAL all of which are upcase whereas in F_HADSTRK variable actually has propcase values so the ideal way to make your second code work is as below &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTABC;
	if F_&amp;amp;disease = "Yes" THEN OUTPUT &amp;amp;YES;
	if F_&amp;amp;disease = "No" THEN OUTPUT &amp;amp;NO;
	if F_&amp;amp;disease = "Total" THEN OUTPUT &amp;amp;ALLTOTAL;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also to make your first code work try below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTaBC;
	SELECT (F_&amp;amp;DISEASE);
		WHEN ("Yes") 	OUTPUT &amp;amp;YES;
		WHEN ("No")	OUTPUT &amp;amp;NO;
		WHEN ("TOTAL'")	OUTPUT &amp;amp;ALLTOTAL;
		OTHERWISE;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Jun 2020 09:17:26 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2020-06-21T09:17:26Z</dc:date>
    <item>
      <title>Extraction of data using select () when or if then.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663784#M198221</link>
      <description>&lt;P&gt;Hi all, I'm trying to extract values from a surveyfreq procedure using two types of code structure and they both give out 0 observations. Below are the two statement types.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;First&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTaBC;
	SELECT (F_&amp;amp;DISEASE);
		WHEN ('&amp;amp;YES') 	OUTPUT &amp;amp;YES;
		WHEN ('&amp;amp;NO')	OUTPUT &amp;amp;NO;
		WHEN ('TOTAL')	OUTPUT &amp;amp;ALLTOTAL;
		OTHERWISE;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Second&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTABC;
	if F_&amp;amp;disease = "YES" THEN OUTPUT &amp;amp;YES;
	if F_&amp;amp;disease = "NO" THEN OUTPUT &amp;amp;NO;
	if F_&amp;amp;disease = "TOTAL" THEN OUTPUT &amp;amp;ALLTOTAL;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What am I doing wrong?&amp;nbsp; I included the dataset and the log when i run the code.&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 01:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663784#M198221</guid>
      <dc:creator>sas_apprenant</dc:creator>
      <dc:date>2020-06-21T01:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extraction of data using select () when or if then.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663786#M198223</link>
      <description>In case of when the macro vars are in single quotes. So they are not resolved. Use double qoutes instead. &lt;BR /&gt;In the case of if did you try checking the case of values and if the values have padded blanks?</description>
      <pubDate>Sun, 21 Jun 2020 02:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663786#M198223</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-21T02:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extraction of data using select () when or if then.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663816#M198237</link>
      <description>&lt;P&gt;What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt;&amp;nbsp;says.&lt;/P&gt;
&lt;P&gt;On top of it: I'd always also add an output table for "otherwise" so you collect what doesn't get selected by any of the other conditions.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 08:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663816#M198237</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-21T08:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extraction of data using select () when or if then.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663817#M198238</link>
      <description>&lt;P&gt;There are two issues in your code&lt;/P&gt;
&lt;P&gt;1) I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214340"&gt;@smantha&lt;/a&gt; , one reason is you need to use " " to resolve the macro variable and used to subset&lt;/P&gt;
&lt;P&gt;2) Also the important thing i noticed is that though your second code is correct, it did not work and the reason is because that the macro variables resolved to YES, NO and TOTAL all of which are upcase whereas in F_HADSTRK variable actually has propcase values so the ideal way to make your second code work is as below &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTABC;
	if F_&amp;amp;disease = "Yes" THEN OUTPUT &amp;amp;YES;
	if F_&amp;amp;disease = "No" THEN OUTPUT &amp;amp;NO;
	if F_&amp;amp;disease = "Total" THEN OUTPUT &amp;amp;ALLTOTAL;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also to make your first code work try below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA &amp;amp;YES	&amp;amp;NO	  &amp;amp;ALLTOTAL;
	SET COMBINEALLtesTaBC;
	SELECT (F_&amp;amp;DISEASE);
		WHEN ("Yes") 	OUTPUT &amp;amp;YES;
		WHEN ("No")	OUTPUT &amp;amp;NO;
		WHEN ("TOTAL'")	OUTPUT &amp;amp;ALLTOTAL;
		OTHERWISE;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Jun 2020 09:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663817#M198238</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-21T09:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extraction of data using select () when or if then.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663828#M198240</link>
      <description>&lt;P&gt;Thank you. I designated the macro variables as upcase rather than the proper case, that's on me. However, I'd like to ask, of the two codes, which do you consider the most effective? Why is that? I am still learning the coding language and would rather distill my codes to efficient and simple statements rather than convoluted ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 10:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extraction-of-data-using-select-when-or-if-then/m-p/663828#M198240</guid>
      <dc:creator>sas_apprenant</dc:creator>
      <dc:date>2020-06-21T10:46:15Z</dc:date>
    </item>
  </channel>
</rss>

