<?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: Proc Contents of Directory/Library Compute variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387430#M277329</link>
    <description>&lt;P&gt;I don't see the relationship of resp_rate to your original question. As far as I can tell from looking at your code, I have provided an answer to your original question.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Aug 2017 17:19:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-08-11T17:19:56Z</dc:date>
    <item>
      <title>Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387405#M277322</link>
      <description>&lt;P&gt;I am trying to compute the same variables across an library of datasets. &amp;nbsp; The problem is, the month and year vars are not included in the files. &amp;nbsp;The code below interpreds year and month from the file name and is supposed to insert yy for year, and mm for month into the file as new variables. &amp;nbsp;However, the code listed below is inserting year and month as the year and month of the most recent file read on the last dataset. &amp;nbsp;Any suggestions?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%Macro Libdata;&lt;BR /&gt;libname rtot 'H:/...../.../RTOT';&lt;BR /&gt;libname test 'H:/...../.../Test';&lt;/P&gt;
&lt;P&gt;proc contents data=rtot._all_ memtype=data out=out noprint;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=out;&lt;BR /&gt;by memname name; run;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;set out;&lt;BR /&gt;by memname name;&lt;BR /&gt;if first.memname;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set a end=last;&lt;BR /&gt;by memname name;&lt;BR /&gt;call symput('DS'|| left(_n_),trim(memname));&lt;BR /&gt;call symput('yy',substr(memname,10,2)); /*Var Year is not found in summary data*/&lt;BR /&gt;call symput('mm',substr(memname,12,2)); /*Month is not found in summary data*/&lt;BR /&gt;if last then call symput('TOTAL',left(_n_));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;total;&lt;BR /&gt;data test.&amp;amp;&amp;amp;DS&amp;amp;i;&lt;BR /&gt;set rtot.&amp;amp;&amp;amp;DS&amp;amp;i;&lt;BR /&gt;if count gt 0 then resp_rate=round(usable/count*100,1);&lt;BR /&gt;cv=round(cv,.01);&lt;BR /&gt;exp_tot=round(exp_tot,1);&lt;BR /&gt;MON="&amp;amp;mm"; /*insert month into file*/&lt;BR /&gt;Yr="&amp;amp;yy"; /*insert year into file*/&lt;BR /&gt;Crop=substr(Varname1,2,3);&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend Libdata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Credits to:&amp;nbsp;*&lt;A href="http://www2.sas.com/proceedings/sugi27/p084-27.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi27/p084-27.pdf&lt;/A&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387405#M277322</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T16:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387408#M277323</link>
      <description>Sample file name are as listed:&lt;BR /&gt;CA_RTTOTS1707&lt;BR /&gt;HG_RTTOTS1403&lt;BR /&gt;HG_RTTOTS1606&lt;BR /&gt;SH_RTTOTS1201&lt;BR /&gt;HG_RTTOTS1203&lt;BR /&gt;AY_RTTOTS1406&lt;BR /&gt;HG_RTTOTS1609&lt;BR /&gt;SH_RTTOTS1301&lt;BR /&gt;HG_RTTOTS1409&lt;BR /&gt;AS_RTTOTS1612&lt;BR /&gt;SH_RTTOTS1401&lt;BR /&gt;HG_RTTOTS1703&lt;BR /&gt;SH_RTTOTS1501</description>
      <pubDate>Fri, 11 Aug 2017 16:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387408#M277323</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T16:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387417#M277324</link>
      <description>&lt;PRE&gt;data _null_;
set a end=last;
by memname name;
call symput('DS'|| left(_n_),trim(memname));
call symput('yy',substr(memname,10,2)); /*Var Year is not found in summary data*/
call symput('mm',substr(memname,12,2)); /*Month is not found in summary data*/
if last then call symput('TOTAL',left(_n_));
run;&lt;/PRE&gt;
&lt;P&gt;Here's your problem. Each time the data set executes the current observation, it assigns a value to &amp;amp;yy and to &amp;amp;mm, and when it executes the last observation, this value for &amp;amp;yy and &amp;amp;mm is all that is available in future steps of your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want each observation of the data set to have it's own &amp;amp;yy and its own &amp;amp;mm then you probably need to have something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;call symput('yy'||left(_n_),substr(memname,10,2));&lt;/PRE&gt;
&lt;P&gt;and similarly adjust the calls to &amp;amp;yy later on in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 16:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387417#M277324</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-11T16:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387418#M277325</link>
      <description>Page, the computations work such that the other vars are updated.  The MON and YY are still coming in as 01 17.  Is it possible these values are coming from a permanent Mac definition library?&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387418#M277325</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T17:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387419#M277326</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2434"&gt;@jakestat&lt;/a&gt; wrote:&lt;BR /&gt;Page, the computations work such that the other vars are updated. &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you please be specific about what you mean? What other variables are updated?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387419#M277326</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-11T17:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387420#M277327</link>
      <description>The computed variables  such as resp_rate;</description>
      <pubDate>Fri, 11 Aug 2017 17:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387420#M277327</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T17:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387423#M277328</link>
      <description>... and please forgive the missing 'i' in your name. Thank you Paige.</description>
      <pubDate>Fri, 11 Aug 2017 17:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387423#M277328</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T17:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387430#M277329</link>
      <description>&lt;P&gt;I don't see the relationship of resp_rate to your original question. As far as I can tell from looking at your code, I have provided an answer to your original question.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387430#M277329</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-11T17:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387437#M277330</link>
      <description>Thank you Paige.  All files have a new time stamp, the new variables are present but the month and year are static. That is the reason I asked if it is possible that a global permanent var definition is over writing it. &lt;BR /&gt;&lt;BR /&gt;Here is the log of the first file written:&lt;BR /&gt;   cpu time            0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;MPRINT(LIBDATA):   data _null_;&lt;BR /&gt;MPRINT(LIBDATA):   set a end=last;&lt;BR /&gt;MPRINT(LIBDATA):   by memname name;&lt;BR /&gt;MPRINT(LIBDATA):   call symput('DS'|| left(_n_),trim(memname));&lt;BR /&gt;MPRINT(LIBDATA):   call symput('yy'|| left(_n_),substr(memname,10,2));&lt;BR /&gt;MPRINT(LIBDATA):   call symput('mm'|| left(_n_),substr(memname,12,2));&lt;BR /&gt;MPRINT(LIBDATA):   if last then call symput('TOTAL',left(_n_));&lt;BR /&gt;MPRINT(LIBDATA):   run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;      2:110   2:155   2:208   3:22&lt;BR /&gt;NOTE: There were 90 observations read from the data set WORK.A.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;      real time           0.01 seconds&lt;BR /&gt;      cpu time            0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;SYMBOLGEN:  Macro variable TOTAL resolves to 90&lt;BR /&gt;MLOGIC(LIBDATA):  %DO loop beginning; index variable I; start value is 1; stop value is 90; by value is 1.&lt;BR /&gt;SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN:  Macro variable DS1 resolves to AS_RTTOTS0612&lt;BR /&gt;MPRINT(LIBDATA):   data test.AS_RTTOTS0612;&lt;BR /&gt;SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN:  Macro variable DS1 resolves to AS_RTTOTS0612&lt;BR /&gt;MPRINT(LIBDATA):   set rtot.AS_RTTOTS0612;&lt;BR /&gt;MPRINT(LIBDATA):   if count gt 0 then resp_rate=round(usable/count*100,1);&lt;BR /&gt;MPRINT(LIBDATA):   cv=round(cv,.01);&lt;BR /&gt;MPRINT(LIBDATA):   exp_tot=round(exp_tot,1);&lt;BR /&gt;SYMBOLGEN:  Macro variable MM resolves to 01&lt;BR /&gt;MPRINT(LIBDATA):   MON="01";&lt;BR /&gt;SYMBOLGEN:  Macro variable YY resolves to 17&lt;BR /&gt;MPRINT(LIBDATA):   Yr="17";&lt;BR /&gt;MPRINT(LIBDATA):   Crop=substr(Varname1,2,3);&lt;BR /&gt;MPRINT(LIBDATA):   run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;      Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;      16879 at 1947:96    15274 at 1947:119&lt;BR /&gt;NOTE: There were 89268 observations read from the data set RTOT.AS_RTTOTS0612.&lt;BR /&gt;NOTE: The data set TEST.AS_RTTOTS0612 has 89268 observations and 44 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;      real time           0.55 seconds&lt;BR /&gt;      cpu time            0.15 seconds&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387437#M277330</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T17:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387439#M277331</link>
      <description>&lt;P&gt;This fixed it.... needed a double &amp;amp;&amp;amp;mm&amp;amp;i.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MON="&amp;amp;&amp;amp;mm&amp;amp;i"; /*insert month into file*/&lt;BR /&gt;Yr="&amp;amp;&amp;amp;yy&amp;amp;i"; /*insert year into file*/&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387439#M277331</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T17:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Contents of Directory/Library Compute variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387445#M277332</link>
      <description>Thank you for your help Paige.</description>
      <pubDate>Fri, 11 Aug 2017 18:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Contents-of-Directory-Library-Compute-variables/m-p/387445#M277332</guid>
      <dc:creator>jakestat</dc:creator>
      <dc:date>2017-08-11T18:04:57Z</dc:date>
    </item>
  </channel>
</rss>

