<?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: SAS macro variable to hold all values of a field in a SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628362#M185662</link>
    <description>&lt;P&gt;thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;. Few urls below I am not able to open because of company policy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway , you can post sample code snippet to achieve this. Please let me know if my question is not clear to you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i was trying to read all values into a single macro variable like, below but i am getting error because length of macro variable .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ERROR: The length of the value of the macro variable NAME (65540) exceeds the maximum length (65534). The value has been truncated to 65534 &lt;/U&gt;&lt;BR /&gt;&lt;U&gt;characters.&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select codename into :name separated by "','" from  test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So my plan was , after reading these .sas codes into a macro variable, i would apply some kind find or search function&amp;nbsp; on each of them , to look for that particular string in them. But I am not getting a proper way to handle this.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2020 22:05:04 GMT</pubDate>
    <dc:creator>suchismita</dc:creator>
    <dc:date>2020-02-28T22:05:04Z</dc:date>
    <item>
      <title>SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628328#M185639</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a sas dataset that contains list of .sas file names in a column called &lt;STRONG&gt;codename.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;My task is to read them one by one and then look for a particular string (something like a specific macro variable or a procedure) .&lt;/P&gt;&lt;P&gt;If the string is there , then I will only filter those .sas files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as an example, let's say below are two values in &lt;STRONG&gt;codename&lt;/STRONG&gt; column, I want these two file paths to be read one by one and a search/find function (similar to &lt;STRONG&gt;grep&lt;/STRONG&gt; in linux) should be executed on them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;codename&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;/path1/codes/proj1/test1.sas&lt;BR /&gt;/path2/codes/proj3/test1/program/test7.sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please suggest.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 20:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628328#M185639</guid>
      <dc:creator>suchismita</dc:creator>
      <dc:date>2020-02-28T20:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628335#M185643</link>
      <description>&lt;P&gt;1. First get it working on one file. Here's an example of how to search a file from SAS&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/26cf789d6da0ce941e447022fdccf0f4" target="_blank"&gt;https://gist.github.com/statgeek/26cf789d6da0ce941e447022fdccf0f4&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Figure out how to automate that for all your files - usually using a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114973"&gt;@suchismita&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sas dataset that contains list of .sas file names in a column called &lt;STRONG&gt;codename.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;My task is to read them one by one and then look for a particular string (something like a specific macro variable or a procedure) .&lt;/P&gt;
&lt;P&gt;If the string is there , then I will only filter those .sas files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as an example, let's say below are two values in &lt;STRONG&gt;codename&lt;/STRONG&gt; column, I want these two file paths to be read one by one and a search/find function (similar to &lt;STRONG&gt;grep&lt;/STRONG&gt; in linux) should be executed on them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;codename&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;/path1/codes/proj1/test1.sas&lt;BR /&gt;/path2/codes/proj3/test1/program/test7.sas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please suggest.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 20:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628335#M185643</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-28T20:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628362#M185662</link>
      <description>&lt;P&gt;thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;. Few urls below I am not able to open because of company policy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway , you can post sample code snippet to achieve this. Please let me know if my question is not clear to you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i was trying to read all values into a single macro variable like, below but i am getting error because length of macro variable .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ERROR: The length of the value of the macro variable NAME (65540) exceeds the maximum length (65534). The value has been truncated to 65534 &lt;/U&gt;&lt;BR /&gt;&lt;U&gt;characters.&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select codename into :name separated by "','" from  test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So my plan was , after reading these .sas codes into a macro variable, i would apply some kind find or search function&amp;nbsp; on each of them , to look for that particular string in them. But I am not getting a proper way to handle this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 22:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628362#M185662</guid>
      <dc:creator>suchismita</dc:creator>
      <dc:date>2020-02-28T22:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628366#M185665</link>
      <description>&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; said, get you code to work on one file without macros, before trying anything with macros.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 22:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628366#M185665</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-28T22:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628368#M185666</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This code will search text files for a single word, search_string
Originally via @schmuel here:
https://communities.sas.com/t5/Base-SAS-Programming/Searching-SAS-code-for-keywords/m-p/390472#M93671
*/

%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&amp;amp;root.sas_help/*.&amp;amp;suffix"); 

data results;
     length fname _filepath $200;
     infile finp filename = _filepath eov=_eov truncover;
     input a_line $200.;
     fname = _filepath;
     
     if _eov=1 then do;
       _n=0;

       _eov=0;
     end;
     _n+1;
     
     if find(a_line,"&amp;amp;search_string",'i')
     then output;
     keep _n a_line fname;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro tutorials are harder to link because they're either rendered Jupyter Notebooks or HTML files. Sorry. You can try accessing the material on a non work computer/device?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 22:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628368#M185666</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-28T22:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628370#M185668</link>
      <description>&lt;P&gt;The FILEVAR option of the INFILE statement will let you use your data without having to make macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  fname=codename;
  infile code filevar=fname end=eof;
  found=0;
  do while (not eof and not found);
    input;
    if find(_infile_,'some string','i') then found=1;
  end;
  keep codepath found;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 22:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628370#M185668</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-28T22:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro variable to hold all values of a field in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628470#M185716</link>
      <description>&lt;P&gt;Untested, but an idea of how to extend&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;nice clean solution to multiple words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let searchWords = apple, banana, pears;

data want ;
  set have ;
  fname=codename;
  nWords = countw("&amp;amp;searchWords");
  
  infile code filevar=fname end=eof;
  found=0;
  do while (not eof and not found);
    input;
    do i=1 to nWords while (not found);
       str = scan("&amp;amp;searchWords", i, ",");
       if find(_infile_, str ,'i') then found=1;
    end;
  end;
  keep codepath found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Feb 2020 19:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-variable-to-hold-all-values-of-a-field-in-a-SAS/m-p/628470#M185716</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-29T19:28:15Z</dc:date>
    </item>
  </channel>
</rss>

