<?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: Substring and input finctions in a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531464#M145462</link>
    <description>&lt;P&gt;Presumably, you are talking about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substr(subj1&amp;amp;i, 1, 4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language resolves first, and SAS sees the result only.&amp;nbsp; For example, when &amp;amp;i is 1, SAS sees:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substr(subj11, 1, 4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This causes SAS to look for a variable named subj11 (which I presume doesn't exist).&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jan 2019 19:01:35 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-01-30T19:01:35Z</dc:date>
    <item>
      <title>Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531372#M145419</link>
      <description>&lt;P&gt;I have the following data set which is being processed within a macro:&lt;/P&gt;&lt;P&gt;id time ipred occ sid&lt;BR /&gt;subj1 0 0&lt;BR /&gt;subj1 0.5 0&lt;BR /&gt;subj1 1 0&lt;BR /&gt;subj1 2 0&lt;BR /&gt;subj1 3 0&lt;BR /&gt;subj1 4 0&lt;BR /&gt;subj1 5 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to:&lt;/P&gt;&lt;P&gt;1.take a substring of the variable subj1 to have a result of 1.&amp;nbsp; How can this be done when the substring is a value within the id column?&lt;/P&gt;&lt;P&gt;2.I tried to convert id from a character to numeric value using sid=input(id,8.) but a s you can see it is converted but the column entries are missing.&amp;nbsp; What am I doing wrong to cause the column entries to be missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included my code which is part of a Macro.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
/*16)**************TEST CONCENTRATIONS************************/
data simt&amp;amp;i._&amp;amp;j; 
retain  _name_ cln lagn ka1n ka2n vfn fn ;
set nall_final&amp;amp;i._&amp;amp;j;
if Treat in ('ATES') ;
if _n_=2;
do time=0, 0.5,1,2,3,4,5,6,7,8,9,10,12,14,16,18,20,24;
/*DOSE IS IN NG AND CP IN NG/ML*/
dose=40000;  
 
	
cln=input (cl,8.);
rename cln=cl;
lagn= input (lag,8.);
rename lagn= lag;
ka1n=input (ka1,8.);
rename ka1n=ka1; 
ka2n=input (ka2,8.);
rename ka2n=ka2;
vfn=input (vf,8.);
rename vfn=vf;
fn=input (logit,8.);
rename fn=f; 
id=input(_name_,8.);
rename _name_=id;
drop id cl lag ka1 ka2 vf logit;
substr(subj1&amp;amp;i,1,4);
sid=input (id,8.);

output ;
	   end;

run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jan 2019 14:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531372#M145419</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-01-30T14:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531379#M145422</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;PLEASE&lt;/FONT&gt;&lt;/STRONG&gt; do &lt;EM&gt;always&lt;/EM&gt; post example data in a &lt;EM&gt;working&lt;/EM&gt; data step with datalines; right now it's very hard to make sense of your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id time ipred occ sid&lt;BR /&gt;subj1 0 0&lt;BR /&gt;subj1 0.5 0&lt;BR /&gt;subj1 1 0&lt;BR /&gt;subj1 2 0&lt;BR /&gt;subj1 3 0&lt;BR /&gt;subj1 4 0&lt;BR /&gt;subj1 5 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as you seem to have 5 variables, but the last two of them are always missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(subj1&amp;amp;i,1,4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will throw a syntax error. substr() must either be a part of an expression (right side of an assignment, or in a condition), or be used on the left side of an assignment, but you don't have one here. Since your variable is already called subj1, the resolution of macro variable &amp;amp;i (which I take to be a counter of a %do loop) will result in a variable you do not have on your dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start out with a piece of &lt;U&gt;&lt;EM&gt;working&lt;/EM&gt;&lt;/U&gt; Base SAS code before you wrap it into a macro definition.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 14:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531379#M145422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-30T14:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531380#M145423</link>
      <description>&lt;P&gt;As you have seen, the INPUT function can't read "subj" as numeric.&amp;nbsp; If you want to get just the digits, use COMPRESS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id2 = compress(id, , 'kd');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KD means keep only the digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That value can be converted to numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id3 = input(id2, 8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you could combine these into one statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id3 = input(compress(id, , 'kd'), 8.);&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 14:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531380#M145423</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-30T14:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531449#M145452</link>
      <description>Please see the reply I received from Astounding (Esteemed Advisor) which I&lt;BR /&gt;will post and answered my question with code that is operates inside the&lt;BR /&gt;Macro.&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2019 17:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531449#M145452</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-01-30T17:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531452#M145453</link>
      <description>&lt;P&gt;Your code worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a follow-up question.&amp;nbsp; Is there a reason that my original code using substr didn't work?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 17:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531452#M145453</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-01-30T17:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Substring and input finctions in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531464#M145462</link>
      <description>&lt;P&gt;Presumably, you are talking about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substr(subj1&amp;amp;i, 1, 4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language resolves first, and SAS sees the result only.&amp;nbsp; For example, when &amp;amp;i is 1, SAS sees:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substr(subj11, 1, 4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This causes SAS to look for a variable named subj11 (which I presume doesn't exist).&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 19:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-and-input-finctions-in-a-Macro/m-p/531464#M145462</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-30T19:01:35Z</dc:date>
    </item>
  </channel>
</rss>

