<?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: call symput with conditional clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692444#M210960</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that instructions in a data step are executed for each iteration of the data step.&lt;/P&gt;
&lt;P&gt;Since the macrovariable name you declare in the call symputs are not observation dependant,&lt;/P&gt;
&lt;P&gt;&amp;amp;status. will be overwritten at each iteration and will eventually be equal to the value&lt;/P&gt;
&lt;P&gt;for the last observation of the dataset. If you really want the value for the last observation,&lt;/P&gt;
&lt;P&gt;you don't need to read the whole dataset. See for instance :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/td-p/8404" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/td-p/8404&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you want to create one macrovariable per observation, youcan suffix their&lt;/P&gt;
&lt;P&gt;names with the observation number :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx(cats('statut_',_N_), Make);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that i used symputx instead of symput as it strips the string in argument before exporting it&lt;/P&gt;
&lt;P&gt;into a macrovariable, which is generally what is wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your test, since you are comparing strings, you can upcase them to avoid rejection&lt;/P&gt;
&lt;P&gt;because of case differences :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if upcase(Make)='VOLKSWAGEN' ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit : A last advice is to carefully check the spelling, which i should have done before writing '&lt;STRONG&gt;W&lt;/STRONG&gt;OLKSWAGEN' &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Oct 2020 08:01:47 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2020-10-19T08:01:47Z</dc:date>
    <item>
      <title>call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692425#M210950</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.cars;
if Make='volkswagan'  then call symput("Status",'Available');
else call symput("Status",'Not Avaialable');
run;
%put &amp;amp;Status.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it shows wrong&amp;nbsp; output&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 07:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692425#M210950</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-10-19T07:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692428#M210952</link>
      <description>&lt;P&gt;Check the variable "Make" - i am 100% sure that it never has the value "volkswagan".&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 06:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692428#M210952</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-10-19T06:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692431#M210954</link>
      <description>IF NOT AVAILABLE IT SHOULD BE SHOWS IN NOT AVAILABLE IN LOG WINDOW AS PER THE IF ELSE CONDITION</description>
      <pubDate>Mon, 19 Oct 2020 06:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692431#M210954</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-10-19T06:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692434#M210956</link>
      <description>&lt;P&gt;Read the log (Maxim 2) and the documentation (Maxim 1) of&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1j60arf27ll4nn1ejavv3nby4pa.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;IF&lt;/A&gt;, and you will qickly find out what is missing.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 06:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692434#M210956</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-19T06:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692438#M210958</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure the code you have posted to this forum is the code you are using?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I try submitting the posted code I get a syntax error indicating what is wrong with the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please copy the code you have posted and run it in SAS to see if you get anything different to what you were running yourself, then,&amp;nbsp; if necessary, edit the original question to show the code you are running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are not receiving any error message then please post your log showing the code and log messages using the "insert code" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 07:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692438#M210958</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-10-19T07:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692444#M210960</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that instructions in a data step are executed for each iteration of the data step.&lt;/P&gt;
&lt;P&gt;Since the macrovariable name you declare in the call symputs are not observation dependant,&lt;/P&gt;
&lt;P&gt;&amp;amp;status. will be overwritten at each iteration and will eventually be equal to the value&lt;/P&gt;
&lt;P&gt;for the last observation of the dataset. If you really want the value for the last observation,&lt;/P&gt;
&lt;P&gt;you don't need to read the whole dataset. See for instance :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/td-p/8404" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-output-last-observation-of-a-SAS-data-set/td-p/8404&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you want to create one macrovariable per observation, youcan suffix their&lt;/P&gt;
&lt;P&gt;names with the observation number :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx(cats('statut_',_N_), Make);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that i used symputx instead of symput as it strips the string in argument before exporting it&lt;/P&gt;
&lt;P&gt;into a macrovariable, which is generally what is wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your test, since you are comparing strings, you can upcase them to avoid rejection&lt;/P&gt;
&lt;P&gt;because of case differences :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if upcase(Make)='VOLKSWAGEN' ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit : A last advice is to carefully check the spelling, which i should have done before writing '&lt;STRONG&gt;W&lt;/STRONG&gt;OLKSWAGEN' &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 08:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692444#M210960</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-10-19T08:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692449#M210964</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.cars;
if Make='volkswagan'  then call symput("Status",'Available');
else call symput("Status",'Not Avaialable');
run;
%put &amp;amp;Status.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it shows wrong&amp;nbsp; output&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;WHAT OUTPUT ARE YOU EXPECTING?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 08:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692449#M210964</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-19T08:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692450#M210965</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;IF NOT AVAILABLE IT SHOULD BE SHOWS IN NOT AVAILABLE IN LOG WINDOW AS PER THE IF ELSE CONDITION&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you're using SAS EG or DMS, read the doc on the data step debugger.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 08:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692450#M210965</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-19T08:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692451#M210966</link>
      <description>&lt;P&gt;Now that you have added the necessary THEN, the step will run, but only the result of the last observation will end up in the macro variable. Since you also have quite incorrect spelling of the compare string, this will always be&lt;/P&gt;
&lt;PRE&gt;Not Avaialable&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2020 08:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692451#M210966</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-19T08:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with conditional clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692592#M211007</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
set sashelp.cars;
if Make='volkswagan'  then call symput("Status",'Available');
else call symput("Status",'Not Avaialable');
run;
%put &amp;amp;Status.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it shows wrong&amp;nbsp; output&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And just what should be the right output???&lt;/P&gt;
&lt;P&gt;I get "Not Avaialable"&amp;nbsp; (your spelling not mine) with the above code.&lt;/P&gt;
&lt;P&gt;Since this leaves the STATUS as of the very last record in the input data set are you sure that is what you wanted?&lt;/P&gt;
&lt;P&gt;The last make in the data set is Volvo so even without the incorrect spelling of "volkswagen" you will never get 'Available' as a result.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 15:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-symput-with-conditional-clause/m-p/692592#M211007</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-19T15:16:31Z</dc:date>
    </item>
  </channel>
</rss>

