<?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 dynamic macro from proc freq chunk in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813579#M321124</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/346341"&gt;@adamqureshi_21&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, now I have to comment, I think you should do this without macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
    set import;
    prefix=substr(record_id,1,2);
run;
proc freq data=intermediate;
    tables prefix*(sex ethnicity age);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 May 2022 19:15:18 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-05-16T19:15:18Z</dc:date>
    <item>
      <title>Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813559#M321109</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that contains the variable record_id. I am using the substr() function to filter by the first two numbers in this record_id variable and using a proc freq to create some tables. Example shown below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data = import;
tables sex ethnicity age;
where substr(record_id,1,2)='14';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I would like to do is create a macro that changes the value of the substring to numbers between 13 - 19, as that encompasses all the prefixes for the record ID's. I'm completely inexperienced with macros so I'm not sure how to go about doing this, and I'm not sure whether to create a macro that encompasses the whole proc freq statement, or just the value of the substring. Any tips or help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813559#M321109</guid>
      <dc:creator>adamqureshi_21</dc:creator>
      <dc:date>2022-05-16T18:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813566#M321116</link>
      <description>&lt;P&gt;How about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis(string=);
proc freq data = import;
tables sex ethnicity age;
where substr(record_id,1,2)="&amp;amp;string";
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 18:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813566#M321116</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T18:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813573#M321121</link>
      <description>That worked perfectly! It looks like I was just overthinking this. Thank you so much!&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Adam</description>
      <pubDate>Mon, 16 May 2022 19:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813573#M321121</guid>
      <dc:creator>adamqureshi_21</dc:creator>
      <dc:date>2022-05-16T19:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813579#M321124</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/346341"&gt;@adamqureshi_21&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, now I have to comment, I think you should do this without macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
    set import;
    prefix=substr(record_id,1,2);
run;
proc freq data=intermediate;
    tables prefix*(sex ethnicity age);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 19:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813579#M321124</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T19:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813584#M321128</link>
      <description>Ah I see, that seems arguably easier. Thank you for this!</description>
      <pubDate>Mon, 16 May 2022 20:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813584#M321128</guid>
      <dc:creator>adamqureshi_21</dc:creator>
      <dc:date>2022-05-16T20:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dynamic macro from proc freq chunk</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813637#M321144</link>
      <description>&lt;P&gt;Even shorter which takes advantage only wanting the first two characters. The format applied will have the output show just the first two characters. No need for additional variables or data set.&lt;/P&gt;
&lt;PRE&gt;proc freq data=import;
    tables record_id*(sex ethnicity age);
    format record_id $2. ;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 23:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dynamic-macro-from-proc-freq-chunk/m-p/813637#M321144</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-16T23:21:25Z</dc:date>
    </item>
  </channel>
</rss>

