<?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 Adding a variable to a Title in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833746#M329607</link>
    <description>&lt;P&gt;I am trying to automate a title to include information from a table into a title. So I am using a macro to define the selection criteria that I am given.&lt;/P&gt;&lt;P&gt;%let id=123456&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in the report I need to call that id# and return 2 specific pieces of information from the table. In an sql statement it would be written as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select name, filenumber&lt;/P&gt;&lt;P&gt;from table1&lt;BR /&gt;where id=&amp;amp;id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I need to take the name and filenumber and put these into the title.&lt;/P&gt;&lt;P&gt;Title1 "Report for &amp;amp;name &amp;amp;filenumber"&lt;/P&gt;&lt;P&gt;This of course doesn't work but is the closest information I have ben able to find.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 22:08:11 GMT</pubDate>
    <dc:creator>hobus</dc:creator>
    <dc:date>2022-09-15T22:08:11Z</dc:date>
    <item>
      <title>Adding a variable to a Title</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833746#M329607</link>
      <description>&lt;P&gt;I am trying to automate a title to include information from a table into a title. So I am using a macro to define the selection criteria that I am given.&lt;/P&gt;&lt;P&gt;%let id=123456&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in the report I need to call that id# and return 2 specific pieces of information from the table. In an sql statement it would be written as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select name, filenumber&lt;/P&gt;&lt;P&gt;from table1&lt;BR /&gt;where id=&amp;amp;id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I need to take the name and filenumber and put these into the title.&lt;/P&gt;&lt;P&gt;Title1 "Report for &amp;amp;name &amp;amp;filenumber"&lt;/P&gt;&lt;P&gt;This of course doesn't work but is the closest information I have ben able to find.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 22:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833746#M329607</guid>
      <dc:creator>hobus</dc:creator>
      <dc:date>2022-09-15T22:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a variable to a Title</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833751#M329608</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name, filenumber into :m_name, :m_fileNumber
from table1
where id=&amp;amp;id;
quit;

title1 "Report for &amp;amp;m_name &amp;amp;m_fileNumber";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something like that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434012"&gt;@hobus&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to automate a title to include information from a table into a title. So I am using a macro to define the selection criteria that I am given.&lt;/P&gt;
&lt;P&gt;%let id=123456&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the report I need to call that id# and return 2 specific pieces of information from the table. In an sql statement it would be written as:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select name, filenumber&lt;/P&gt;
&lt;P&gt;from table1&lt;BR /&gt;where id=&amp;amp;id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I need to take the name and filenumber and put these into the title.&lt;/P&gt;
&lt;P&gt;Title1 "Report for &amp;amp;name &amp;amp;filenumber"&lt;/P&gt;
&lt;P&gt;This of course doesn't work but is the closest information I have ben able to find.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name = Alfred;
proc sql noprint;
select age, sex into :m_age, :m_sex from sashelp.class where name = "&amp;amp;name";
quit;

%put &amp;amp;m_age.;
%put &amp;amp;m_sex.;

Title1 "Report for &amp;amp;name, Age = &amp;amp;m_age, Sex = &amp;amp;m_sex";
proc print data=sashelp.class noobs label;
where name = "&amp;amp;name";
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 22:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833751#M329608</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-15T22:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a variable to a Title</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833753#M329609</link>
      <description>&lt;P&gt;IF, and that is a big if in many cases, the Name and Filenumber values you want have a single one value for the given id:&lt;/P&gt;
&lt;P&gt;INTO is the instruction in SQL to place values into macro variables. Also not the use of : preceding the name of the macro variable. The distinct may be overkill but if you have multiple records with the same name and filenumber.&amp;nbsp; I used different macro variable names so you can see where the macro variable appears easier. Data set variables and macro variables my get confused at some point and having different names sometimes helps follow code instead of "Name" appear in many places.&lt;/P&gt;
&lt;PRE&gt;%let id=123456;

Proc sql noprint;
   select distinct name, filenumber into : namevar, : numvar
   from table1
   where id = &amp;amp;id.;
quit;

Title1 "Report for &amp;amp;namevar. &amp;amp;numvar.";&lt;/PRE&gt;
&lt;P&gt;If a variable is truly numeric you may want to control the conversion with a Put(numericvar, &amp;lt;someformat&amp;gt; -L) . The default conversion that SAS would use is a best12. format and the result will be right justified which can place a lot of spaces before your variable.&lt;/P&gt;
&lt;P&gt;You can see that in this example where the first Age has a bunch of spaces in the output.&lt;/P&gt;
&lt;PRE&gt;%let id=Alice;

Proc sql noprint;
   select distinct sex, age, put(age,best5. -L) into: namevar, :numvar1, :numvar2
   from sashelp.class
   where name = "&amp;amp;id.";
quit;

%put Namevar=&amp;amp;namevar  numvar1=&amp;amp;numvar1 numvar2=&amp;amp;numvar2;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 22:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-variable-to-a-Title/m-p/833753#M329609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-15T22:44:38Z</dc:date>
    </item>
  </channel>
</rss>

