<?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 proc sql macrovariables treatment in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131484#M35747</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I would like to summary the variable treatment: drug, placebo of the next dataset have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp; treatment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; placebo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; placebo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using this syntax:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select treatment, count (distinct subjid) as count&lt;/P&gt;&lt;P&gt;from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will get :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;placebo&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drug&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But my idea is using proc sql , i will keep these values 2, and 3 in diffrent macrovariables using proc sql with the option (into), &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i need the syntax to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;V&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;variabels&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 02 Jun 2012 14:44:12 GMT</pubDate>
    <dc:creator>michtka</dc:creator>
    <dc:date>2012-06-02T14:44:12Z</dc:date>
    <item>
      <title>proc sql macrovariables treatment</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131484#M35747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I would like to summary the variable treatment: drug, placebo of the next dataset have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp; treatment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; placebo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; placebo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using this syntax:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select treatment, count (distinct subjid) as count&lt;/P&gt;&lt;P&gt;from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will get :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;placebo&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drug&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But my idea is using proc sql , i will keep these values 2, and 3 in diffrent macrovariables using proc sql with the option (into), &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i need the syntax to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;V&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;variabels&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Jun 2012 14:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131484#M35747</guid>
      <dc:creator>michtka</dc:creator>
      <dc:date>2012-06-02T14:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql macrovariables treatment</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131485#M35748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry...i missed the group&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select treatment, count (distinct subjid) as count&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by treatment; &lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Jun 2012 14:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131485#M35748</guid>
      <dc:creator>michtka</dc:creator>
      <dc:date>2012-06-02T14:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql macrovariables treatment</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131486#M35749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get them assigned to a series of macro variables this way, but make sure you can recreate the order to match them up later with the proper treatments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;select count(distinct subjid) into :ntrt1 - :ntrt2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; group by treatment&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; order by treatment&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two issues with this.&lt;/P&gt;&lt;P&gt;First you will get a warning about grouping by a variable that is not included in the selection list.&lt;/P&gt;&lt;P&gt;You can either also pull out the treatments into another macro variable array (if it is useful for you), or if you do not need it just shove into a dummy macro variable to suppress the warning.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select treatment,count(distinct subjid) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; into dummy,:ntrt1 - :ntrt2&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by treatment&lt;/P&gt;&lt;P&gt;&amp;nbsp; order by treatment&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice that the list of macro variables is after the INTO keyword and separated by commas just like the list of values that starts the select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other problem is how many macro variables will you need?&amp;nbsp; If you are creating generic code then that might not be known in advance.&amp;nbsp; You can give it an extreme value for the upperrange in the INTO clause and it will only create the macro variables that it needs.&amp;nbsp; You can then reference the automatic macro variable SQLOBS to find how many groups there were.&lt;/P&gt;&lt;P&gt;Combining these we could create two macro variable arrays (TRTxx and NTRTxx) and the count (NTRTGRP) using this statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;select&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; treatment&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,count(distinct subjid) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; into :trt1 - :trt200&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , :ntrt1 - :ntrt200&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; group by treatment&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; order by treatment&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let ntrtgrp = &amp;amp;sqlobs ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Jun 2012 15:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-macrovariables-treatment/m-p/131486#M35749</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-06-02T15:21:44Z</dc:date>
    </item>
  </channel>
</rss>

