<?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: Use different select value in proc sql based on variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522867#M142006</link>
    <description>&lt;P&gt;Thank you everyone for your replies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;novinosrin,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This worked exactly like i needed it too.&amp;nbsp; Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 13:59:55 GMT</pubDate>
    <dc:creator>jerry898969</dc:creator>
    <dc:date>2018-12-20T13:59:55Z</dc:date>
    <item>
      <title>Use different select value in proc sql based on variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522712#M141957</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a program that I run manually for different years.&amp;nbsp; The sas data table for almost all are in one directory structure and then I have another directory structure for some of the other years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ex.&lt;/P&gt;
&lt;P&gt;2000-2005 C:\Data\Checking\SAS\Proj1&lt;/P&gt;
&lt;P&gt;2006-2009 C:\Data\Checking\SAS\Proj2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The table I want is in that path for that specific year.&amp;nbsp; The issue I have is that one column is different between the two locations.&lt;/P&gt;
&lt;P&gt;I have State in the first path and ST in the tables in the second path.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;This is what I have tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2009 ;
%macro path ;    
	%if &amp;amp;year. &amp;lt; 2006 %then %let vName = state ;	
	%else %let vName = st ;		
%mend path ;
%path ;

%put &amp;amp;vName. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to manually change these field names in my selects statements.&amp;nbsp; What would be the best way to define a macro variable that will hold either State or ST and use that in my select statements throughout my program?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My example above is giving me&amp;nbsp; "WARNING: Apparent symbolic reference VNAME not resolved." on %put &amp;amp;vName. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql ;&lt;/P&gt;
&lt;P&gt;select &amp;amp;vname.&lt;/P&gt;
&lt;P&gt;from tblTest&lt;/P&gt;
&lt;P&gt;quit ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 21:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522712#M141957</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2018-12-19T21:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use different select value in proc sql based on variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522718#M141960</link>
      <description>&lt;P&gt;Try this. This code would conditionally check the year and determines the libname based on the year range and renames the field ST to State only if the year is between 2006 and 2009.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Path1 "C:\Data\Checking\SAS\Proj1";
Libname Path2 "C:\Data\Checking\SAS\Proj2";

%let year=2009;

%macro resolve_dates;
	%if %eval(&amp;amp;year &amp;gt;= 2000 ) &amp;amp;&amp;amp; %eval( &amp;amp;year &amp;lt;=  2005) %then
		%do;

			Data want;
				set path1.have;
			run;

		%end;
	%else %if %eval( &amp;amp;year&amp;gt;=2006) &amp;amp;&amp;amp; %eval(&amp;amp;year  &amp;lt;= 2009) %then
		%do;

			Data want;
				set path2.have(rename=(ST=state));
			run;

		%end;
%mend;

%resolve_dates&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 22:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522718#M141960</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-19T22:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use different select value in proc sql based on variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522722#M141963</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16835"&gt;@jerry898969&lt;/a&gt;&amp;nbsp; That is because your vName is a local macro variable. Globalise it like --&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let year=2009 ;
%macro path ; 
	%global vName; 
	%if &amp;amp;year. &amp;lt; 2006 %then %let vName = state ;	
	%else %let vName = st ;		
%mend path ;
%path ;

%put &amp;amp;vName. ;&lt;/CODE&gt;&lt;/PRE&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/16835"&gt;@jerry898969&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My example above is giving me&amp;nbsp;&lt;STRONG&gt; "WARNING: Apparent symbolic reference VNAME not resolved." on %put &amp;amp;vName. ;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql ;&lt;/P&gt;
&lt;P&gt;select &amp;amp;vname.&lt;/P&gt;
&lt;P&gt;from tblTest&lt;/P&gt;
&lt;P&gt;quit ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 22:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522722#M141963</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-19T22:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use different select value in proc sql based on variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522757#M141977</link>
      <description>&lt;P&gt;Try this..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2009 ;
%macro path ;
%let vName = sex ;	 

%if %eval(&amp;amp;year.&amp;lt;2006) %then %let vName = name ;	

proc sql ;
  select &amp;amp;vname.
  from sashelp.class
quit ;
%mend path ;

%path ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Changes made are the following:&lt;/P&gt;&lt;P&gt;1. Using %eval&lt;/P&gt;&lt;P&gt;2. Moved the&amp;nbsp;proc step inside the macro (if you want to skip the %global macro variable declaration)&lt;/P&gt;&lt;P&gt;3. When year is different then we change the value to be used for macro variable vName.&amp;nbsp; For this case, I can give macro variable a default value.&amp;nbsp; The value will change when your %if condition has been satisfied.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 00:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522757#M141977</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-12-20T00:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use different select value in proc sql based on variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522867#M142006</link>
      <description>&lt;P&gt;Thank you everyone for your replies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;novinosrin,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This worked exactly like i needed it too.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 13:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-different-select-value-in-proc-sql-based-on-variable/m-p/522867#M142006</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2018-12-20T13:59:55Z</dc:date>
    </item>
  </channel>
</rss>

