<?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: choose unique proc/data steps based on value of variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158271#M30897</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do this using macro. Here is an example you can modify this based on your own variable. Dataset "have" 3 variables one of them is gender, processing is being done based on values of gender variable. Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input gender $ age :3.1 height weight @@;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;f 143 56.3&amp;nbsp; 85.0 f 155 62.3 105.0 f 153 63.3 108.0 f 161 59.0&amp;nbsp; 92.0&lt;BR /&gt;f 191 62.5 112.5 f 171 62.5 112.0 f 185 59.0 104.0 f 142 56.5&amp;nbsp; 69.0&lt;BR /&gt;f 160 62.0&amp;nbsp; 94.5 f 140 53.8&amp;nbsp; 68.5 f 139 61.5 104.0 f 178 61.5 103.5&lt;BR /&gt;f 157 64.5 123.5 f 149 58.3&amp;nbsp; 93.0 f 143 51.3&amp;nbsp; 50.5 f 145 58.8&amp;nbsp; 89.0&lt;BR /&gt;m 164 66.5 112.0 m 189 65.0 114.0 m 164 61.5 140.0 m 167 62.0 107.5&lt;BR /&gt;m 151 59.3&amp;nbsp; 87.0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;%macro process(dsname);&lt;BR /&gt;proc sql;&lt;BR /&gt;select quote(trim(gender)) into :g from &amp;amp;dsname where gender='f';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if &amp;amp;g="f" %then %do;&lt;/P&gt;&lt;P&gt;proc means data=&amp;amp;dsname;&lt;BR /&gt;var height weight;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;data want; &lt;BR /&gt;set &amp;amp;dsname;&lt;BR /&gt;ratio=weight/height;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend process;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%process(have)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 28 Jun 2014 10:46:43 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-06-28T10:46:43Z</dc:date>
    <item>
      <title>choose unique proc/data steps based on value of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158267#M30893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have a variable that has 2 values.&amp;nbsp; for value a, i want to do a series of procs and data steps.&amp;nbsp; for value b, i want to do a different set of procs/data steps.&amp;nbsp; both sets of procs/data steps are in 1 sas program.&amp;nbsp; how to i do this&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 13:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158267#M30893</guid>
      <dc:creator>borovy</dc:creator>
      <dc:date>2014-06-27T13:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: choose unique proc/data steps based on value of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158268#M30894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, a few methods spring to mind.&amp;nbsp; Macros would be one, code generation another.&amp;nbsp; For macros:&lt;/P&gt;&lt;P&gt;%macro Do_steps_A();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...do some steps;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%macro Do_steps_B();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... do some steps;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if test="A" then call execute('%do_steps_a;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else call execute('%do_steps_b;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the code generation its pretty much the same except instead of calling the macro in the call execute you put the actual code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 13:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158268#M30894</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-27T13:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: choose unique proc/data steps based on value of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158269#M30895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or if you have SAS 9.3 M2 or newer, you can use: DOSUBL() routine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 13:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158269#M30895</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-06-27T13:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: choose unique proc/data steps based on value of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158270#M30896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I probably don't understand your requirement but may be you're after something as simple as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=have(where=(variable='value1'));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=have(where=(variable='value2'));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jun 2014 03:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158270#M30896</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-06-28T03:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: choose unique proc/data steps based on value of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158271#M30897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do this using macro. Here is an example you can modify this based on your own variable. Dataset "have" 3 variables one of them is gender, processing is being done based on values of gender variable. Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input gender $ age :3.1 height weight @@;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;f 143 56.3&amp;nbsp; 85.0 f 155 62.3 105.0 f 153 63.3 108.0 f 161 59.0&amp;nbsp; 92.0&lt;BR /&gt;f 191 62.5 112.5 f 171 62.5 112.0 f 185 59.0 104.0 f 142 56.5&amp;nbsp; 69.0&lt;BR /&gt;f 160 62.0&amp;nbsp; 94.5 f 140 53.8&amp;nbsp; 68.5 f 139 61.5 104.0 f 178 61.5 103.5&lt;BR /&gt;f 157 64.5 123.5 f 149 58.3&amp;nbsp; 93.0 f 143 51.3&amp;nbsp; 50.5 f 145 58.8&amp;nbsp; 89.0&lt;BR /&gt;m 164 66.5 112.0 m 189 65.0 114.0 m 164 61.5 140.0 m 167 62.0 107.5&lt;BR /&gt;m 151 59.3&amp;nbsp; 87.0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;%macro process(dsname);&lt;BR /&gt;proc sql;&lt;BR /&gt;select quote(trim(gender)) into :g from &amp;amp;dsname where gender='f';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if &amp;amp;g="f" %then %do;&lt;/P&gt;&lt;P&gt;proc means data=&amp;amp;dsname;&lt;BR /&gt;var height weight;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;data want; &lt;BR /&gt;set &amp;amp;dsname;&lt;BR /&gt;ratio=weight/height;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend process;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%process(have)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jun 2014 10:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/choose-unique-proc-data-steps-based-on-value-of-variable/m-p/158271#M30897</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-06-28T10:46:43Z</dc:date>
    </item>
  </channel>
</rss>

