<?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: output sas statements into macro variable to resolve to desired output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617726#M181065</link>
    <description>&lt;P&gt;You haven't shown us the code inside %RTF&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jan 2020 11:52:14 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-01-16T11:52:14Z</dc:date>
    <item>
      <title>output sas statements into macro variable to resolve to desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/615780#M180157</link>
      <description>&lt;P&gt;I have a macro in which there are keyword parameters like this.&lt;/P&gt;&lt;P&gt;colvars=C1 C3 C6 ,&lt;BR /&gt;collabl1=SCLC|(N=&amp;amp;m_C1)|n(%),&lt;BR /&gt;collabl2=NSCLC|Non-Squamous|(N=&amp;amp;m_C3)|n(%),&lt;BR /&gt;collabl3=GEJ|(N=&amp;amp;m_C6)|n(%),&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This will assign my title column lables in my output report.&lt;/P&gt;&lt;P&gt;I want to automate this by getting the number of variables in the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are 4 vars in the data it should automate by knowing there are 4 variables in the dataset and get that information into the macro.&lt;/P&gt;&lt;P&gt;colvars=C1 C2 C3 C5 ,&lt;BR /&gt;collabl1=SCLC|(N=&amp;amp;m_C1)|n(%),&lt;BR /&gt;collabl2=NSCLC|Squamous|(N=&amp;amp;m_C2)|n(%),&lt;/P&gt;&lt;P&gt;collabl3=ESCC|(N=&amp;amp;m_C3)|n(%),&lt;BR /&gt;collabl4=GEJ|(N=&amp;amp;m_C6)|n(%),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to automate this and get these steps into the macro call, based on the number of variables in the dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;%rtf(inds=final,&lt;BR /&gt;rowheadvars=rowhead1 rowhead2,&lt;BR /&gt;rowheadlabel=,&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;colvars=C1 C3 C6 Czz, &lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;collabl1=SCLC|(N=&amp;amp;m_C1)|n(%),&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;collabl2=NSCLC|Non-Squamous|(N=&amp;amp;m_C3)|n(%),&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;collabl3=GEJ|(N=&amp;amp;m_C6)|n(%),&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;collabl4=Total|(N=&amp;amp;m_Czz)|n(%),&lt;BR /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt;colwidths=39 15 15 15 15, &lt;/EM&gt;&lt;EM&gt;&lt;BR /&gt;lindent=700,&lt;BR /&gt;sortordvars=varord ordvar1,&lt;BR /&gt;linespp=18,&lt;BR /&gt;orientation=landscape&lt;BR /&gt;);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created the list of vars and the count of vars but couldnt able to figure out how to iterate them into the macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;final is the dataset from which i am taking the nonmissing vars.&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select distinct name&lt;BR /&gt;into :vars separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where memname = 'FINAL' and prxmatch("m/C1|C2|C3|C4|C5|C6|CZZ/oi",strip(name))&amp;gt; 0&lt;BR /&gt;order by varnum;&lt;BR /&gt;quit;&lt;BR /&gt;%let cntlist = &amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;%put &amp;amp;vars. ;&lt;BR /&gt;%put &amp;amp;cntlist. ;&lt;BR /&gt;&lt;BR /&gt;options mlogic mprint symbolgen;&lt;BR /&gt;%macro wordcount(list);&lt;/P&gt;&lt;P&gt;%local count;&lt;BR /&gt;%let count=0;&lt;BR /&gt;%do %while(%qscan(&amp;amp;list,&amp;amp;count+1,%str( )) ne %str());&lt;BR /&gt;%let count = %eval(&amp;amp;count+1);&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format ;&lt;/P&gt;&lt;P&gt;value $chrt&lt;BR /&gt;"C1" = "SCLC"&lt;BR /&gt;"C2" = "NSCLC|Squamous"&lt;BR /&gt;"C3" = "NSCLC|Non-Squamous"&lt;BR /&gt;"C4" = "HNSCC"&lt;BR /&gt;"C5" = "ESCC"&lt;BR /&gt;"C6" = "GEJ";&lt;/P&gt;&lt;P&gt;"CZZ" = "Total";&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 20:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/615780#M180157</guid>
      <dc:creator>yashraj89</dc:creator>
      <dc:date>2020-01-07T20:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: output sas statements into macro variable to resolve to desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617716#M181060</link>
      <description>&lt;P&gt;You put the labels into a format, good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you can use SQL to get the labels as well, that way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global collab1 collab2 collab3 collab4 collab5 collab6 collab7;
proc sql noprint;
  select distinct name, cats(putc(name,'$chrt.'),'|(N=',symget('M_'!!name),')|n(%)')
  into :vars separated by ' ',:collab1-:collab7 trimmed
  from dictionary.columns
  where memname = 'FINAL' and libname ='WORK' and 
             prxmatch("m/C1|C2|C3|C4|C5|C6|CZZ/oi",strip(name))&amp;gt; 0
  order by varnum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added the libname to the WHERE clause, as you will have problems otherwise if you have a table called FINAL in another library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started by declaring the macro variables first, otherwise only the ones that are actually written to will be created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should then be able to call your macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rtf(inds=final,
rowheadvars=rowhead1 rowhead2,
rowheadlabel=,
colvars=&amp;amp;vars,
collabl1=&amp;amp;Collab1,
collabl2=&amp;amp;Collab2,
collabl3=&amp;amp;collab3,
...etc&amp;nbsp;up&amp;nbsp;to&amp;nbsp;collabl7=&amp;amp;Collab7&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the macro is your own, you can also put the SQL call to get the variables inside the macro, and drop the parameters; the SQL call should just be adjusted to get the variable names from the right table, depending on the INDS parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not have to write a macro to get the word count from a list, just use %sysfunc(Countw(&amp;amp;vars)). Or you can get the number of rows read from dictionary.columns by looking at the automatic macro variable SQLOBS.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 10:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617716#M181060</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-01-16T10:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: output sas statements into macro variable to resolve to desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617726#M181065</link>
      <description>&lt;P&gt;You haven't shown us the code inside %RTF&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 11:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617726#M181065</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-16T11:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: output sas statements into macro variable to resolve to desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617854#M181131</link>
      <description>&lt;P&gt;Why does the macro call have only one parameter to supply the columns (names?) but many separate parameters to supply the headers?&amp;nbsp; Why not do the same thing for the headers?&amp;nbsp; Just use some other delimiter character, like a back slash.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%rtf
(inds=final
,rowheadvars=rowhead1 rowhead2
,rowheadlabel=
,colvars=C1 C2 C3 C5 
,collabels
=SCLC|(N=&amp;amp;m_C1)|n(%)
\NSCLC|Squamous|(N=&amp;amp;m_C2)|n(%)
\ESCC|(N=&amp;amp;m_C3)|n(%)
\GEJ|(N=&amp;amp;m_C6)|n(%)
....
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 18:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-sas-statements-into-macro-variable-to-resolve-to-desired/m-p/617854#M181131</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-16T18:13:27Z</dc:date>
    </item>
  </channel>
</rss>

