<?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 loop and creating date format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51179#M13997</link>
    <description>Hello &lt;BR /&gt;
&lt;BR /&gt;
I have a library with datasets for jan to dec for 2009. Within each dataset is a variable called filedate whose type is numeric and gives date in the form of 20090131. &lt;BR /&gt;
&lt;BR /&gt;
I would like to know how to programm such that I can run a loop to read the files one by one from the library for all 12 months and create a new variable called date which should have a sas date format showing me the date as 200901 - so basically it should give me the year and the month.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
    <pubDate>Tue, 02 Feb 2010 20:56:21 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-02-02T20:56:21Z</dc:date>
    <item>
      <title>loop and creating date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51179#M13997</link>
      <description>Hello &lt;BR /&gt;
&lt;BR /&gt;
I have a library with datasets for jan to dec for 2009. Within each dataset is a variable called filedate whose type is numeric and gives date in the form of 20090131. &lt;BR /&gt;
&lt;BR /&gt;
I would like to know how to programm such that I can run a loop to read the files one by one from the library for all 12 months and create a new variable called date which should have a sas date format showing me the date as 200901 - so basically it should give me the year and the month.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 02 Feb 2010 20:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51179#M13997</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-02-02T20:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: loop and creating date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51180#M13998</link>
      <description>Your SAS version and OS platform is not clear with your post - it is always useful to provide this information - suggestion for next time.&lt;BR /&gt;
&lt;BR /&gt;
You can use the FILENAME statement with the PIPE access method to define your input file naming criteria.  And you can use the FILEVAR= parameter on the INFILE statement to identify each incoming file name so you can assign a SAS numeric DATE variable and use a suitable output FORMAT to display the date as desired (you mentioned yyyymm).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Recommended Google advanced search argument this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
filename pipe read files directory site:sas.com</description>
      <pubDate>Tue, 02 Feb 2010 22:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51180#M13998</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-02T22:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: loop and creating date format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51181#M13999</link>
      <description>If these are sas datasets in a sas library, then you could use the SAS9.2 option for SET statements INDSNAME= which names a variable to hold the name of the dataset which contributes to that iteration. &lt;BR /&gt;
Supposing all of that and your data sets are named  Tcrat01 - Tcra12 and contain accounting data sorted by ac_no, then this selects only ac_no beginning 'ABC' (at the same point you can use some more relevant filter) but places their rows in account and fileDate order ;[pre] data selected ;&lt;BR /&gt;
    set yourlib.tcrat1-yourlib.tcrat12 INDSNAME= in_table ;&lt;BR /&gt;
    by ac_no filedate ;&lt;BR /&gt;
    where ac_no =: 'ABC' ;[/pre]* now convert number like date into sas date ;[pre]    date = input( put( filedate, z8. ), yymmdd8.) ;&lt;BR /&gt;
    format date yymmN6. ;[/pre]* now copy the indsn= info to another variable to keep it in the output table;[pre]    from_set = in_table ;&lt;BR /&gt;
 run ;[/pre]&lt;BR /&gt;
If your "library" is not a sas library but a folder or pds (on mvs) then there is some similar functionality on the INFILE statement, for handling external files, like FILENAME= and FILEVAR=, but I hope we're talking sas datasets here.&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
PeterC</description>
      <pubDate>Wed, 03 Feb 2010 11:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/loop-and-creating-date-format/m-p/51181#M13999</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-02-03T11:28:12Z</dc:date>
    </item>
  </channel>
</rss>

