<?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 CALL Execute in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/CALL-Execute/m-p/227368#M5480</link>
    <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate mean of a dependent variable by categories of character variables and then replace categories with mean score. In other words, the new variables will be created with suffix _C for categorical variables and it contains mean score of dependent variable for each categories. I have written a sas macro but i am having difficulty executing last step i.e. replacing mean scores by categories. I know this can be done with 'call execute'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data abcd;&lt;BR /&gt;input x y$ z a$;&lt;BR /&gt;cards;&lt;BR /&gt;73.9 C 12 E&lt;BR /&gt;15.96 B 20 F&lt;BR /&gt;92.84 A 9 E&lt;BR /&gt;88.4 D 16 F&lt;BR /&gt;40.44 C 4 B&lt;BR /&gt;9.85 B 9 C&lt;BR /&gt;54.79 B 2 C&lt;BR /&gt;88.19 E 16 E&lt;BR /&gt;98.04 D 18 F&lt;BR /&gt;35.85 F 15 F&lt;BR /&gt;15.69 E 3 F&lt;BR /&gt;88.6 F 16 C&lt;BR /&gt;33.71 B 14 A&lt;BR /&gt;83.19 C 3 D&lt;BR /&gt;68.99 E 5 C&lt;BR /&gt;28.15 B 17 A&lt;BR /&gt;56.92 A 14 A&lt;BR /&gt;84.21 A 13 D&lt;BR /&gt;91.07 E 7 A&lt;BR /&gt;51.76 E 4 F&lt;BR /&gt;57.38 D 16 A&lt;BR /&gt;69.96 E 3 C&lt;BR /&gt;17.81 D 20 A&lt;BR /&gt;18.59 E 6 A&lt;BR /&gt;17.31 C 4 A&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want all categories of variable 'a' to be recoded with the following&amp;nbsp;values (mean scores) into a new column(suffix _c). The same should be done for variable 'y' with their mean scores.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" summary="Page Layout" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl63" style="height: 15.0pt; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;a_c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;A&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;40.1175&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;B&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;40.44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;C&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;58.438&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;D&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;83.7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;E&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;84.9767&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl67" style="height: 15.75pt; border-top: none; width: 48pt;"&gt;F&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;50.95&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro categ(input=, depvar=,output=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Get library and dataset name; &lt;BR /&gt;data _null_; &lt;BR /&gt;call symput ("library", put(upcase(substr("&amp;amp;input",1,index("&amp;amp;input",'.')-1)), $8.)); &lt;BR /&gt;call symput ("datset", put(upcase(substr("&amp;amp;input",index("&amp;amp;input",'.')+1,length("&amp;amp;input"))), $32.)); &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select name into : vars separated by " "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where LIBNAME = "WORK"&lt;BR /&gt;and MEMNAME = "ABCD"&lt;BR /&gt;and type = "char";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n=%sysfunc(countw(&amp;amp;vars));&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%let val = %scan(&amp;amp;vars,&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data = abcd noprint nway;&lt;BR /&gt;class &amp;amp;val.;&lt;BR /&gt;var &amp;amp;depvar.;&lt;BR /&gt;output out= temp_&amp;amp;val. (drop = _type_ _freq_) mean= ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%categ(input=work.abcd, depvar=x, output=abcd2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2015 22:33:49 GMT</pubDate>
    <dc:creator>Ujjawal</dc:creator>
    <dc:date>2015-09-25T22:33:49Z</dc:date>
    <item>
      <title>CALL Execute</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/CALL-Execute/m-p/227368#M5480</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate mean of a dependent variable by categories of character variables and then replace categories with mean score. In other words, the new variables will be created with suffix _C for categorical variables and it contains mean score of dependent variable for each categories. I have written a sas macro but i am having difficulty executing last step i.e. replacing mean scores by categories. I know this can be done with 'call execute'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data abcd;&lt;BR /&gt;input x y$ z a$;&lt;BR /&gt;cards;&lt;BR /&gt;73.9 C 12 E&lt;BR /&gt;15.96 B 20 F&lt;BR /&gt;92.84 A 9 E&lt;BR /&gt;88.4 D 16 F&lt;BR /&gt;40.44 C 4 B&lt;BR /&gt;9.85 B 9 C&lt;BR /&gt;54.79 B 2 C&lt;BR /&gt;88.19 E 16 E&lt;BR /&gt;98.04 D 18 F&lt;BR /&gt;35.85 F 15 F&lt;BR /&gt;15.69 E 3 F&lt;BR /&gt;88.6 F 16 C&lt;BR /&gt;33.71 B 14 A&lt;BR /&gt;83.19 C 3 D&lt;BR /&gt;68.99 E 5 C&lt;BR /&gt;28.15 B 17 A&lt;BR /&gt;56.92 A 14 A&lt;BR /&gt;84.21 A 13 D&lt;BR /&gt;91.07 E 7 A&lt;BR /&gt;51.76 E 4 F&lt;BR /&gt;57.38 D 16 A&lt;BR /&gt;69.96 E 3 C&lt;BR /&gt;17.81 D 20 A&lt;BR /&gt;18.59 E 6 A&lt;BR /&gt;17.31 C 4 A&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want all categories of variable 'a' to be recoded with the following&amp;nbsp;values (mean scores) into a new column(suffix _c). The same should be done for variable 'y' with their mean scores.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" summary="Page Layout" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl63" style="height: 15.0pt; width: 48pt;"&gt;a&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;a_c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;A&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;40.1175&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;B&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;40.44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;C&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;58.438&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;D&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;83.7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;E&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl66" style="border-top: none; border-left: none; width: 48pt;"&gt;84.9767&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl67" style="height: 15.75pt; border-top: none; width: 48pt;"&gt;F&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;50.95&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro categ(input=, depvar=,output=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Get library and dataset name; &lt;BR /&gt;data _null_; &lt;BR /&gt;call symput ("library", put(upcase(substr("&amp;amp;input",1,index("&amp;amp;input",'.')-1)), $8.)); &lt;BR /&gt;call symput ("datset", put(upcase(substr("&amp;amp;input",index("&amp;amp;input",'.')+1,length("&amp;amp;input"))), $32.)); &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select name into : vars separated by " "&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where LIBNAME = "WORK"&lt;BR /&gt;and MEMNAME = "ABCD"&lt;BR /&gt;and type = "char";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n=%sysfunc(countw(&amp;amp;vars));&lt;BR /&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%let val = %scan(&amp;amp;vars,&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data = abcd noprint nway;&lt;BR /&gt;class &amp;amp;val.;&lt;BR /&gt;var &amp;amp;depvar.;&lt;BR /&gt;output out= temp_&amp;amp;val. (drop = _type_ _freq_) mean= ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%categ(input=work.abcd, depvar=x, output=abcd2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 22:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/CALL-Execute/m-p/227368#M5480</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-09-25T22:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: CALL Execute</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/CALL-Execute/m-p/227370#M5481</link>
      <description>&lt;P&gt;One approach: &amp;nbsp;Instead of using a CLASS statement in PROC MEANS, sort and use a BY statement. &amp;nbsp;Then it becomes a simple matter to re-combine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge abcd temp_&amp;amp;val (rename=(&amp;amp;depvar=&amp;amp;depvar._c));&lt;/P&gt;&lt;P&gt;by &amp;amp;val;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you take that approach, it's not really necessary to select a significant name for the output data set from PROC MEANS. &amp;nbsp;Just call it STATS, and merge it back in. &amp;nbsp;You can reuse the name STATS for the next variable.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 22:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/CALL-Execute/m-p/227370#M5481</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-09-25T22:57:43Z</dc:date>
    </item>
  </channel>
</rss>

