<?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 Check first word of a string list and tranwrd if in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473647#M30714</link>
    <description>&lt;P&gt;I have a variable var which gets filled by a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i need to check if the first word include, lets say XY10Model, if this condition is true i need to replace it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var = Car, Color, XY10Model - string is ok&lt;/P&gt;&lt;P&gt;var = XY10Model, Car, Color - string should be - %let var = Model, Car, Color&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that i can replace the XY10Model with tranwrd, but how to check the first word in var and than replace it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let NewVar = %scan(&amp;amp;var,1) or %let NewVar = %scan(&amp;amp;var,1,",") doesnt work, because of the commas. I have read that it runs in data step, but i need it within that macro or in proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 10:22:54 GMT</pubDate>
    <dc:creator>DEBE</dc:creator>
    <dc:date>2018-06-27T10:22:54Z</dc:date>
    <item>
      <title>Check first word of a string list and tranwrd if</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473647#M30714</link>
      <description>&lt;P&gt;I have a variable var which gets filled by a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i need to check if the first word include, lets say XY10Model, if this condition is true i need to replace it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var = Car, Color, XY10Model - string is ok&lt;/P&gt;&lt;P&gt;var = XY10Model, Car, Color - string should be - %let var = Model, Car, Color&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that i can replace the XY10Model with tranwrd, but how to check the first word in var and than replace it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let NewVar = %scan(&amp;amp;var,1) or %let NewVar = %scan(&amp;amp;var,1,",") doesnt work, because of the commas. I have read that it runs in data step, but i need it within that macro or in proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 10:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473647#M30714</guid>
      <dc:creator>DEBE</dc:creator>
      <dc:date>2018-06-27T10:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Check first word of a string list and tranwrd if</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473650#M30715</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;I have read that it runs in data step, but i need it within that macro or in proc sql." - this statement clearly makes no sense.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Base SAS - this is the programming language and is used for manipulating data&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Macro - this is a purely optional text generation (or find and replace) software for creating text, it does nothing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SQL - this is an optional component which exposes an SQL compiler to the proc sql function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As with all these types of questions, macro is not the best place to store data.&amp;nbsp; Place your elements in a dataset, and use Base SAS to process them.&amp;nbsp; Macro starts becoming incredibly messy as soon as you start doing data processing in it and will break most of the time.&amp;nbsp; Even doing this is preferable:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;%let var=XY10Model, Car, Color;&lt;BR /&gt;&lt;BR /&gt;data _null_;
  line=ifc(substr("&amp;amp;var.",1,4)="XY10",substr("&amp;amp;var.",5),"&amp;amp;var.");
  call symputx('var',line);
run;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;var.;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This will check if the first four letters are XY10 and only take the string after that if so.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 10:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473650#M30715</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-27T10:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Check first word of a string list and tranwrd if</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473706#M30716</link>
      <description>&lt;P&gt;Can you be more specific how your getting those macro variables. If your attempt is to solve it in the way you mentioned then use %BQUOTE(), but there might be other straight forward way to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%let var=XY10Model, Car, Color;
%put &amp;amp;var;
%let Newvar=%scan(%BQUOTE(&amp;amp;var),1,',');
%put &amp;amp;NewVar;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 12:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473706#M30716</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-27T12:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Check first word of a string list and tranwrd if</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473732#M30718</link>
      <description>&lt;P&gt;Through a prompt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That solves to find the first word, now i need to replace it in the string somehow.&lt;/P&gt;&lt;P&gt;Thxs for that SuryaKiran&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473732#M30718</guid>
      <dc:creator>DEBE</dc:creator>
      <dc:date>2018-06-27T13:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Check first word of a string list and tranwrd if</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473963#M30742</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var=XY10Model, Car, Color;
%put &amp;amp;var;
%let Newvar=%sysfunc(prxchange(s/^XY10Model/Model/,1,%bquote(&amp;amp;var)));
%put &amp;amp;NewVar;





%let var=Car, Color, XY10Mode;
%put &amp;amp;var;
%let Newvar=%sysfunc(prxchange(s/^XY10Model/Model/,1,%bquote(&amp;amp;var)));
%put &amp;amp;NewVar;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jun 2018 03:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Check-first-word-of-a-string-list-and-tranwrd-if/m-p/473963#M30742</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-28T03:39:46Z</dc:date>
    </item>
  </channel>
</rss>

