<?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: Creating a variable during a proc freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338960#M77280</link>
    <description>&lt;P&gt;While PROC FREQ doesn't support this, here are a few ideas to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really need a variable, or will some other version of the year be sufficient?&amp;nbsp; For example, YEAR could become part of both the data set label and the variable label:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=clms.allclaims_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables hcfasaf / out=junk.qc_hcfasaf_&amp;amp;year. (label="Counts for &amp;amp;year");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; label hcfasaf = "hcfasaf for &amp;amp;year";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just be sure to use double quotes, not single quotes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you must have a variable, you can add it temporarily to a VIEW to speed up the processing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp / view=temp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set clms.allclaims_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; year = &amp;amp;year;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=temp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables year * hcfasaf / out=junk.qc_hcfasaf_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 19:51:05 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-03-07T19:51:05Z</dc:date>
    <item>
      <title>Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338952#M77274</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to covert this to a proc freq for efficiency, but i can't seem to find code to be able to create a variable at the same time.&amp;nbsp; For all i know it's not allowed.&amp;nbsp; But i thought i'd ask.&amp;nbsp; I can rename stuff, keep stuff, use a where statement.&amp;nbsp; But i can't seem to find code to create a variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Convert...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;create table junk.qc_hcfasaf_&amp;amp;year. as&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;select &amp;amp;year. as year,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;hcfasaf,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;count(hcfasaf) as count&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;from clms.allclaims_&amp;amp;year.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;group by hcfasaf;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;quit;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to....&lt;/P&gt;&lt;P&gt;proc freq data=clms.allclaims_&amp;amp;year.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; tables hcfasaf / out=junk.qc_hcfasaf_&amp;amp;year.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i don't know if i can create a variable during the step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Megan&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338952#M77274</guid>
      <dc:creator>MeganE</dc:creator>
      <dc:date>2017-03-07T19:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338955#M77276</link>
      <description>&lt;P&gt;Aside from variables created by procedures themselves, no new variables can be created. That needs to be done in a data or proc sql step.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338955#M77276</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-07T19:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338960#M77280</link>
      <description>&lt;P&gt;While PROC FREQ doesn't support this, here are a few ideas to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really need a variable, or will some other version of the year be sufficient?&amp;nbsp; For example, YEAR could become part of both the data set label and the variable label:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=clms.allclaims_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables hcfasaf / out=junk.qc_hcfasaf_&amp;amp;year. (label="Counts for &amp;amp;year");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; label hcfasaf = "hcfasaf for &amp;amp;year";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just be sure to use double quotes, not single quotes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you must have a variable, you can add it temporarily to a VIEW to speed up the processing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp / view=temp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set clms.allclaims_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; year = &amp;amp;year;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=temp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables year * hcfasaf / out=junk.qc_hcfasaf_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338960#M77280</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-07T19:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338985#M77292</link>
      <description>&lt;P&gt;No you can't create a new variable in proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But depending on your overall goal there may be another way. It looks like you'll be running this for multiple years?&lt;/P&gt;
&lt;P&gt;I would suggest when you append the final datasets you can extract the year from the table names using the INDSNAME option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set qc_hcfasaf_2001-qc_hcfasaf_2016 indsname = source;

year = scan(source, -1, "_");

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338985#M77292</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-07T20:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338986#M77293</link>
      <description>&lt;P&gt;Perhaps something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=clms.allclaims_&amp;amp;year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables &amp;amp;year*hcfasaf /&amp;nbsp;norow nocol&amp;nbsp;out=junk.qc_hcfasaf_&amp;amp;year. (rename=(&amp;amp;year = year));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/338986#M77293</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-07T20:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable during a proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/339640#M77514</link>
      <description>&lt;P&gt;This is brilliant!&amp;nbsp; I've never heard of indsname before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it'll be running 16 times and i'd rather have one final table than 16, but i need to tell the years apart.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 14:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-during-a-proc-freq/m-p/339640#M77514</guid>
      <dc:creator>MeganE</dc:creator>
      <dc:date>2017-03-09T14:24:35Z</dc:date>
    </item>
  </channel>
</rss>

