<?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: Do loop to run calculations over all data in SAS library in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624524#M20113</link>
    <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Run-data-step-on-all-files-in-directory/m-p/624517#M183993" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Run-data-step-on-all-files-in-directory/m-p/624517#M183993&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Is this homework or something?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Feb 2020 16:44:39 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-13T16:44:39Z</dc:date>
    <item>
      <title>Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624488#M20105</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to find a piece of script that will apply some simple calculations to the entire contents of a SAS library (2,800 files, all of which have the same columns, and are named "_YYYYMMDD").&lt;/P&gt;&lt;P&gt;The calculation itself is straight forward (create a column based on an existing one, change any char values to numeric, and store new column as numeric). I've built this, however I can't find any method of running this on the contents of the library.&lt;/P&gt;&lt;P&gt;I've created a Dictionary which lists all data within the library as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table work.mytables as&lt;BR /&gt;select *&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname = 'B'&lt;BR /&gt;order by memname ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have any ideas how to proceed from here? Thanks.&lt;/P&gt;&lt;P&gt;Using SAS EG8.1&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624488#M20105</guid>
      <dc:creator>gsisme</dc:creator>
      <dc:date>2020-02-13T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624492#M20106</link>
      <description>&lt;P&gt;Are these .txt files? Are these .csv files? Can you give us more information? How are you reading them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are .txt files and maybe if they are .csv files, you can read them all with one SAS data step.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624492#M20106</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-13T15:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624494#M20107</link>
      <description>&lt;P&gt;Apologies, I've imported them to the SAS library and they're stored as SAS files.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624494#M20107</guid>
      <dc:creator>gsisme</dc:creator>
      <dc:date>2020-02-13T15:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624495#M20108</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312011"&gt;@gsisme&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try CALL EXECUTE():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testSet1 testSet2;
  variable = 42;
run;

data YOUR_DICTIONARY;
  datasetnameVariable = 'testSet1'; output;
  datasetnameVariable = 'testSet2'; output;
run;


filename t TEMP;

data _null_;
file t;
input;
put _infile_;
cards4;
/* put your code here */
/*e.g.*/
  
  variable = 100 * variable;
  
/* put your code here */
;;;;
run;

data _null_;
  set YOUR_DICTIONARY;
    call execute('data ' || datasetnameVariable || ';'); 
    call execute('set ' || datasetnameVariable || ';'); 
    call execute('%nrstr(%include t;) run;'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624495#M20108</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-13T15:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624498#M20109</link>
      <description>&lt;P&gt;Other option would be to use %macro instead filename,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro code();
/* put your code here */
/*e.g.*/
  
  variable = 100 * variable;
  
/* put your code here */
%mend code;

data _null_;
  set YOUR_DICTIONARY;
    call execute('data ' || datasetnameVariable || ';'); 
    call execute('set ' || datasetnameVariable || ';'); 
    call execute('%nrstr(%code()) run;'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624498#M20109</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-13T15:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624501#M20110</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312011"&gt;@gsisme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Apologies, I've imported them to the SAS library and they're stored as SAS files.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If they WERE .txt files or .csv files, you still wouldn't need a loop and you wouldn't need the individual SAS data sets. You could read them all with a single DATA step.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624501#M20110</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-13T15:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624503#M20111</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312011"&gt;@gsisme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Apologies, I've imported them to the SAS library and they're stored as SAS files.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm going to take this as meaning that you used proc import. Did you check the status of the variables as they were imported?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you import some sort of text files such as delimited with spaces, commas, tabs or other characters? Were any of these files supposed to have the same structure (same variables, in same order?).&lt;/P&gt;
&lt;P&gt;If so then you really need to read the data with data step code to control the contents. Especially if you had a description document that would indicate what the maximum length of variables would be and the purpose of variables.&lt;/P&gt;
&lt;P&gt;Prevention by reading properly in the first place is much better than trying to fix things later.&lt;/P&gt;
&lt;P&gt;Also you can add the calculation to the step that reads the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would be extremely cautious of any process that does what you ask because it has the potential to cause other issues. There many types of identifiers used that contain only digits but should not be treated as numeric. Sometimes account "numbers" will exceed the length that SAS will store properly. And account numbers should not have any numeric calculations done with them in general.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624503#M20111</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-13T15:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624524#M20113</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Run-data-step-on-all-files-in-directory/m-p/624517#M183993" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Run-data-step-on-all-files-in-directory/m-p/624517#M183993&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Is this homework or something?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 16:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624524#M20113</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-13T16:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624528#M20114</link>
      <description>You started at the wrong place, first figure out how you do what you need for one file and then you generalize that. &lt;BR /&gt;&lt;BR /&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;To automate the task once you have it working you can either use a macro or combine the datasets and do it all at once or several different options but it depends a lot on what you're trying to do overall.</description>
      <pubDate>Thu, 13 Feb 2020 16:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624528#M20114</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-13T16:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop to run calculations over all data in SAS library</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624529#M20115</link>
      <description>Thanks Bart, did exactly what needed.</description>
      <pubDate>Thu, 13 Feb 2020 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Do-loop-to-run-calculations-over-all-data-in-SAS-library/m-p/624529#M20115</guid>
      <dc:creator>gsisme</dc:creator>
      <dc:date>2020-02-13T16:50:07Z</dc:date>
    </item>
  </channel>
</rss>

