<?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 to create Macro Variable using SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786258#M251007</link>
    <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Thu, 16 Dec 2021 04:14:59 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2021-12-16T04:14:59Z</dc:date>
    <item>
      <title>How to create Macro Variable using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786241#M250999</link>
      <description>&lt;P&gt;I have the data with Yes and No responses. How to create the macro variable that gives total count for respective responses. for example in the following dataset I have two IDs with Y response. So I am expecting my macro variable that display the response count.&lt;/P&gt;
&lt;P&gt;data x;&lt;BR /&gt;input id response$;&lt;BR /&gt;cards;&lt;BR /&gt;1 Y&lt;BR /&gt;2 Y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;In this case I am expecting&amp;nbsp; to display the following&lt;/P&gt;
&lt;P&gt;%put &lt;FONT color="#FF6600"&gt;&amp;amp;resp_y&amp;nbsp;&lt;/FONT&gt; &lt;FONT color="#00FF00"&gt;&amp;amp;resp_n; ( I&lt;FONT color="#000000"&gt; don't have any 'N' responses in the dataset but I still want to display 0 , SO, it has to come with 0&amp;nbsp; if there is no count, and want to display the value , if there is a value in future&lt;/FONT&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;2&lt;/FONT&gt; &lt;FONT color="#00FF00"&gt;0&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 22:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786241#M250999</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-15T22:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Macro Variable using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786243#M251000</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input id response $;
cards;
1 Y
2 Y
;
run;

%let Resp_y = 0;
%let Resp_n = 0;

proc sql noprint;
select count(*)
into :Resp_y
from x
where response = 'Y'
;
select count(*)
into :Resp_n
from x
where response = 'N'
;
quit;

%put Resp_y = &amp;amp;Resp_y;
%put Resp_n = &amp;amp;Resp_n; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Dec 2021 22:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786243#M251000</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-12-15T22:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Macro Variable using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786244#M251001</link>
      <description>&lt;P&gt;Thank you for quick response.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 22:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786244#M251001</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-15T22:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Macro Variable using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786249#M251004</link>
      <description>&lt;P&gt;Show what you tried.&lt;/P&gt;
&lt;P&gt;Normally SQL will create the macro variable even if the count is zero.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  input id response $;
cards;
1 Y
2 Y
3 .
;


proc sql noprint;
select count(*)
     , count(response)
     , sum(response = 'Y')
     , sum(response='N')
  into :observations  trimmed
     , :non_missing trimmed
     , :yes trimmed
     , :no trimmed
  from x
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;303   %put &amp;amp;=observations &amp;amp;=non_missing &amp;amp;=yes &amp;amp;=no ;
OBSERVATIONS=3 NON_MISSING=2 YES=2 NO=0

&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Dec 2021 02:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786249#M251004</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-16T02:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Macro Variable using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786258#M251007</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 16 Dec 2021 04:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-Macro-Variable-using-SQL/m-p/786258#M251007</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-16T04:14:59Z</dc:date>
    </item>
  </channel>
</rss>

