<?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: PROC SQL, into Macro variable assignment problems in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370692#M88538</link>
    <description>&lt;P&gt;Hard to tell without sample data so that we know how the input data is formatted, but the most obvious thing to watch out for is extra spaces in the generated macro variables.&lt;/P&gt;
&lt;P&gt;You can add the TRIMMED keyword into the INTO clause to have it automatically trim the values.&lt;/P&gt;
&lt;P&gt;Check out this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select age,age
    into :notrim , :trimmed trimmed
    from sashelp.class (obs=1)
  ;
quit;
%put notrim=|&amp;amp;notrim| trimmed=|&amp;amp;trimmed|;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;notrim=|      14| trimmed=|14|&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Jun 2017 18:18:09 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-06-26T18:18:09Z</dc:date>
    <item>
      <title>PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370689#M88536</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble assigning macro variables that work within the proc sql into function. When I run the code below, the assignment of the macro variable sort of "cuts off" at year, such that the macro variable follows the assignment shown in the picture below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although when I use the basic %let way of assignment, it works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC sql;
		SELECT DISTINCT 
			CASE 
				WHEN month("&amp;amp;ReportDate"d)=12 THEN "('CY 1st Half','CY 2nd Half')" 
				WHEN month("&amp;amp;ReportDate"d)=6 THEN "('CY 1st Half')" 
			END 
		AS period, 
		CASE 
				WHEN month("&amp;amp;ReportDate"d)=12 THEN "YE" 
				WHEN month("&amp;amp;ReportDate"d)=6 THEN "MY" 
			END 
		AS period2, 
		strip(calculated period2) as period3,
strip(substr(compress(tranwrd(put(intnx('qtr',"&amp;amp;ReportDate"d,-1,'E'),yymmdd10.),"-","")),1,4)) as year
into : Period, : Period2, : Period3,  : Year
FROM  _PRODSAVAIL;
quit;
%let libname = \\BPR\BPR 2.0 (New BPR)\Data\&amp;amp;year.\&amp;amp;period3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13989i2B110D1DE3EBE29E/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture.JPG" title="Capture.JPG" /&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370689#M88536</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-26T18:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370691#M88537</link>
      <description>&lt;P&gt;Note that I've managed to solve the problem using the following re-assingment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#004080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%let&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#400080" face="Courier New" size="3"&gt; year= &amp;amp;year; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#004080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%let&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#400080" face="Courier New" size="3"&gt; period = &amp;amp;period3; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#400080" face="Courier New" size="3"&gt;but is there a way to go around that step? &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370691#M88537</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-26T18:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370692#M88538</link>
      <description>&lt;P&gt;Hard to tell without sample data so that we know how the input data is formatted, but the most obvious thing to watch out for is extra spaces in the generated macro variables.&lt;/P&gt;
&lt;P&gt;You can add the TRIMMED keyword into the INTO clause to have it automatically trim the values.&lt;/P&gt;
&lt;P&gt;Check out this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select age,age
    into :notrim , :trimmed trimmed
    from sashelp.class (obs=1)
  ;
quit;
%put notrim=|&amp;amp;notrim| trimmed=|&amp;amp;trimmed|;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;notrim=|      14| trimmed=|14|&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370692#M88538</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-26T18:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370695#M88539</link>
      <description>I tried that and it still causes the same problem. So far the only thing that I found works is reassigning again using %let = &amp;amp;year (weird.)&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370695#M88539</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-26T18:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370697#M88540</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/81770"&gt;@camfarrell25&lt;/a&gt;&amp;nbsp;The TRIMMED option doesn't work for you?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370697#M88540</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-26T18:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL, into Macro variable assignment problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370705#M88541</link>
      <description>ah my mistake!! I'm fairly new at this. I didn't know how to properly use the trimmed option...&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jun 2017 18:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-into-Macro-variable-assignment-problems/m-p/370705#M88541</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-26T18:35:07Z</dc:date>
    </item>
  </channel>
</rss>

