<?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 Way to simplify this code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419868#M103271</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 

create table data_2011 as
select * 
from 'E:\blah blah blah\2011.sas7bdat'
where dx in ('5015' '10383') 
quit; 

proc sql; 

create table data_2012 as
select * 
from 'E:\blah blah blah\2012.sas7bdat'
where dx in ('5015' '10383') 
quit; 

proc sql; 

create table data_2013 as
select * 
from 'E:\blah blah blah\2013.sas7bdat'
where dx in ('5015' '10383') 
quit; 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And so forth. And then I&amp;nbsp;stack them all in a data step...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I do something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let claims = 2011 2012 2013;
%let dx = 5015 10383;

data elig_1;

set %do i=1 %to %sysfunc(countw(&amp;amp;claims.));
%let filename = %scan(%claims., &amp;amp;i.);
&amp;amp;filename.

where dx in %dx.

%end;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does the above code make sense and accomplish the same thing?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Dec 2017 00:23:42 GMT</pubDate>
    <dc:creator>cdubs</dc:creator>
    <dc:date>2017-12-10T00:23:42Z</dc:date>
    <item>
      <title>Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419868#M103271</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 

create table data_2011 as
select * 
from 'E:\blah blah blah\2011.sas7bdat'
where dx in ('5015' '10383') 
quit; 

proc sql; 

create table data_2012 as
select * 
from 'E:\blah blah blah\2012.sas7bdat'
where dx in ('5015' '10383') 
quit; 

proc sql; 

create table data_2013 as
select * 
from 'E:\blah blah blah\2013.sas7bdat'
where dx in ('5015' '10383') 
quit; 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And so forth. And then I&amp;nbsp;stack them all in a data step...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I do something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let claims = 2011 2012 2013;
%let dx = 5015 10383;

data elig_1;

set %do i=1 %to %sysfunc(countw(&amp;amp;claims.));
%let filename = %scan(%claims., &amp;amp;i.);
&amp;amp;filename.

where dx in %dx.

%end;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does the above code make sense and accomplish the same thing?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 00:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419868#M103271</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-10T00:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419875#M103275</link>
      <description>&lt;P&gt;It would only work if you wrapped it in a macro and corrected the inconsistencies. However, the following would do the same thing:&lt;/P&gt;
&lt;PRE&gt;data data_2011;&lt;BR /&gt; input dx;&lt;BR /&gt; cards;&lt;BR /&gt;5015&lt;BR /&gt;10383&lt;BR /&gt;2500&lt;BR /&gt;2600&lt;BR /&gt;50151&lt;BR /&gt;501&lt;BR /&gt;;&lt;BR /&gt;data data_2012;&lt;BR /&gt; input dx;&lt;BR /&gt; cards;&lt;BR /&gt;5015&lt;BR /&gt;10383&lt;BR /&gt;2500&lt;BR /&gt;2600&lt;BR /&gt;50151&lt;BR /&gt;501&lt;BR /&gt;;&lt;BR /&gt;data data_2013;&lt;BR /&gt; input dx;&lt;BR /&gt; cards;&lt;BR /&gt;5015&lt;BR /&gt;10383&lt;BR /&gt;2500&lt;BR /&gt;2600&lt;BR /&gt;50151&lt;BR /&gt;501&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;%let claims = data_2011 data_2012 data_2013;
%let dx = 5015,10383;

data elig_1;
  set &amp;amp;claims.;
  where dx in (&amp;amp;dx.);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 01:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419875#M103275</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-10T01:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419879#M103277</link>
      <description>&lt;P&gt;Why do you have .sas7bdat files with invalid member names?&amp;nbsp; SAS Names must start with either a letter or an underscore.&lt;/P&gt;
&lt;P&gt;You might be able to use membernames of '2012'n and '2013'n if you set the system option validmemname to EXTEND.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validmemname=extend;
libname in 'E:\blah blah blah\';
data elig_1;
  set in.'2012'n in.'2013'n in.'2014'n ;
  where dx in ('5015' '10383');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset names are valid membernames and they have numeric suffixes then you might be able to just a range of membernames instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set in.data2012-in.data2014 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want help in converting space delimited list of words into a list of quoted words then you can try using the TRANWRD() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dxlist=5015 10383;
%let dxlistq="%sysfunc(tranwrd(&amp;amp;dxlist,%str( ),%str(" ")))";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could do a similar thing for you list of dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dslist=2012 2013 2014 ;
%let dslistn=in."%sysfunc(tranwrd(&amp;amp;dxlist,%str( ),%str("n in")))"n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So your data step is then.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data elig_1;
  set &amp;amp;dslistn ;
  where dx in (&amp;amp;dxlistq);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 02:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419879#M103277</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-10T02:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419881#M103279</link>
      <description>&lt;P&gt;Thanks for your response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My SAS knowledge is too rudimentary to understand :(. I'm not sure what an invalid member name is?&lt;BR /&gt;&lt;BR /&gt;I guess the original SAS dataset files are ccaes103, ccaes113, ccaes123... which correspond to 2010, 2011, 2012,...&lt;BR /&gt;&lt;BR /&gt;I ultimately just want to stack them all vertically, but only taking the claims that have dx with those two codes...&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 02:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419881#M103279</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-10T02:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419886#M103281</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174079"&gt;@cdubs&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your response!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My SAS knowledge is too rudimentary to understand :(. I'm not sure what an invalid member name is?&lt;BR /&gt;&lt;BR /&gt;I guess the original SAS dataset files are ccaes103, ccaes113, ccaes123... which correspond to 2010, 2011, 2012,...&lt;BR /&gt;&lt;BR /&gt;I ultimately just want to stack them all vertically, but only taking the claims that have dx with those two codes...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Create a SAS libref that points to the physical directory where&amp;nbsp;the SAS datasets are stored. That will make it easier to refer to them and also make your code more independent of where the files get moved to a larger disk.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname truven 'e:\directoryname';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Write a data step to read the data you want. Start by telling SAS what dataset you want to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diabetes;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then tell it what data to read.&amp;nbsp; if you want to read multiple datasets then use a space delimited list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set truven.ccaes13 truven.ccaes14 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add any statements to limit the observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  where (dx1 like '250%')
     or (dx2 like '250%')
     or (dx3 like '250%')
     or (dx4 like '250%')
     or (dx5 like '250%')
  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can add other data step statements to calculate new variables, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;End the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Dec 2017 03:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419886#M103281</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-10T03:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Way to simplify this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419894#M103284</link>
      <description>&lt;P&gt;Valid SAS names contain only letters, digits, underlines, and must start with a letter or underline.&lt;/P&gt;
&lt;P&gt;Names of physical SAS files that shall be recognized within a defined library must be lowercase. Very important with SAS UE, which runs in a UNIX VM; UNIX is a case-sensitive system.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 07:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-simplify-this-code/m-p/419894#M103284</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-10T07:38:06Z</dc:date>
    </item>
  </channel>
</rss>

