<?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 reading data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257164#M49346</link>
    <description>&lt;P&gt;Thanks.&amp;nbsp;It is working now. And one last thing. how we can treat if the date field is like 2014-08-18 and we need to do the same thing.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Mar 2016 21:39:21 GMT</pubDate>
    <dc:creator>Test_yes</dc:creator>
    <dc:date>2016-03-16T21:39:21Z</dc:date>
    <item>
      <title>SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257112#M49330</link>
      <description>&lt;P&gt;&amp;nbsp;I have 2 variables and 3 records in a sas data set, and based on the date field in that data set, I need to read different monthly data sets. For example, I have item no. Date 1 30Jun2015 2 31Jul2015 3 31Aug2015 When I read the first record, then based on the date field (30jun2015) here, it should merge another dataset suffixed with 30jun2015 with this current dataset. How can I achieve that?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 19:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257112#M49330</guid>
      <dc:creator>Test_yes</dc:creator>
      <dc:date>2016-03-16T19:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257115#M49333</link>
      <description>&lt;P&gt;Please post sample data and expected output.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 19:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257115#M49333</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-16T19:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257116#M49334</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Input dataset1:
item no. Date
1 30Jun2015
2 31Jul2015
3 31Aug2015
Input dataset2:(test_30june2015)
item no phone no
1 1111111111
4
5
Input dataset3:(test_31jul2015)
item no phone no
2 2222222222
7
&amp;nbsp;
Expected output:
item no. Date phone no
1 30Jun2015 1111111111
2 31Jul2015 2222222222
3 31Aug2015&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Mar 2016 20:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257116#M49334</guid>
      <dc:creator>Test_yes</dc:creator>
      <dc:date>2016-03-16T20:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257117#M49335</link>
      <description>One way could be to use call execute in a data step that reads the control table. The call execute could call a macro that does the merging.</description>
      <pubDate>Wed, 16 Mar 2016 19:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257117#M49335</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-16T19:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257158#M49343</link>
      <description>&lt;P&gt;Alternatively, the following approach might work (depending on your real data):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have1;
input item date :date9.;
format date date9.;
cards;
1 30Jun2015
2 31Jul2015
3 31Aug2015
;

data test_30jun2015; /* changed from test_30june2015! */
input item phone;
cards;
1 1111111111
4 .
5 .
;

data test_31jul2015;
input item phone;
cards;
2 2222222222
7 .
; 

/* Select datasets and merge them with HAVE1 */

proc sql noprint;
select 'test_'||put(date,date9.) as dsname into :dslist separated by ' '
from have1
where exist(calculated dsname, 'DATA');
quit;

data want;
merge have1(in=a) &amp;amp;dslist;
by item;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With your sample data, item no. could be used as well to select observations (and the file name &lt;FONT face="courier new,courier"&gt;test_30june2015&lt;/FONT&gt; could be left unchanged):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select item into :itemlist separated by ' '
from have1;
quit;

data want;
merge have1 test_:;
by item;
where item in (&amp;amp;itemlist);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(But this might not be applicable to your real data.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case the above merge steps would create unpleasant INFO messages in the log (if option MSGLEVEL=I):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;INFO: The variable phone on data set WORK.TEST_30JUN2015 will be overwritten by data set WORK.TEST_31JUL2015.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 20:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257158#M49343</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-16T20:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257162#M49344</link>
      <description>&lt;P&gt;Thanks. But how can I change if the date value in the 'have1' datset is like ' 30Jun2015' and the merging dataset as 'test_201506'.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 21:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257162#M49344</guid>
      <dc:creator>Test_yes</dc:creator>
      <dc:date>2016-03-16T21:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257163#M49345</link>
      <description>&lt;P&gt;The following modification could work with character dates and dataset names of the form test_YYYYMM:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have1;
input item date :$9.;
cards;
1 30Jun2015
2 31Jul2015
3 31Aug2015
;

data test_201506;
input item phone;
cards;
1 1111111111
4 .
5 .
;

data test_201507;
input item phone;
cards;
2 2222222222
7 .
; 

/* Select datasets and merge them with HAVE1 */

proc sql noprint;
select 'test_'||compress(put(input(date,date9.),yymm.),'M') as dsname into :dslist separated by ' '
from have1
where exist(calculated dsname, 'DATA');
quit;

data want;
merge have1(in=a) &amp;amp;dslist;
by item;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Mar 2016 21:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257163#M49345</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-16T21:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257164#M49346</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp;It is working now. And one last thing. how we can treat if the date field is like 2014-08-18 and we need to do the same thing.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 21:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257164#M49346</guid>
      <dc:creator>Test_yes</dc:creator>
      <dc:date>2016-03-16T21:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257168#M49347</link>
      <description>&lt;P&gt;In this case, simply replace the informat &lt;FONT face="courier new,courier"&gt;date9.&lt;/FONT&gt;&amp;nbsp;(in the SELECT statement) by &lt;FONT face="courier new,courier"&gt;yymmdd10.&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 21:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257168#M49347</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-16T21:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257196#M49351</link>
      <description>&lt;P&gt;The point is the MERGE BY variale is item and date or just item ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input item date :date9.;
format date date9.;
cards;
1 30Jun2015
2 31Jul2015
3 31Aug2015
;

data test_30jun2015; /* changed from test_30june2015! */
input item phone;
cards;
1 1111111111
4 .
5 .
;

data test_31jul2015;
input item phone;
cards;
2 2222222222
7 .
; 
data test(index=(item date));
 length dsname $ 40;
 set test_: indsname=dsname;
 date=input(scan(dsname,-1,'_'),date9.);
 format date date9.;
run;

data want;
 merge have1(in=ina) test;
 by item date;
 if ina;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Mar 2016 01:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-data/m-p/257196#M49351</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-17T01:46:09Z</dc:date>
    </item>
  </channel>
</rss>

