<?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: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421464#M67966</link>
    <description>&lt;P&gt;Question 1) To be honest, I have seen many implementations of macro lists and such like in over 15years, and there is one consistent thing I have found, they never make code more user friendly or modifiable.&amp;nbsp; First there is rarely any documentation to adequately explain the code or parameters, and secondly due to that, those paramter lists can cause fails and bugs of all kinds in the code.&amp;nbsp; For instance a simple step where the name in the list doesn't exist, will you check for this before your code, what about not containing the expected variables, or the right type, correct values etc.&amp;nbsp; The list goes on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question 2) Data merging (joining) is the means of putting data across the page, based on joining variables.&amp;nbsp; Setting data is the method of setting data one under the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally if you want to make your code more robust, put your data into a set library, then you can apply a list to get all of them without knowing up front:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;compiled  enrollids&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;enrollid&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; raw&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;ccaes:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'123'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'12345'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and age &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;18&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will take all datasets in raw with ccaes prefix.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2017 09:12:35 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-12-15T09:12:35Z</dc:date>
    <item>
      <title>How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420675#M67893</link>
      <description>&lt;P&gt;I have two questions...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Is there a way to simplify the repetitiveness of the PROC SQLs below?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I &lt;U&gt;used repeated proc sqls&lt;/U&gt; to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STEP A) Take out any inpatient claims with the DX codes 123, 12345 and compile them into "compiled" dataset, &lt;U&gt;AND&lt;/U&gt;&lt;/P&gt;&lt;P&gt;STEP B)&amp;nbsp;Take out all eligibility claims from eligibility files if their enrolid shows up in "compiled"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. I think if a patient&amp;nbsp;has enrolID&amp;nbsp;12345 in year 2011, and then loses eligibility,&amp;nbsp;another patient may appear as enrolID 12345. How can I change the code below to make sure &amp;nbsp;STEP B takes out eligibility claims that match on enrolID and a corresponding "year" variable (assuming both eligibility claims and inpatient claims has a common 'year' variable?)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step A and step B in its current state below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*0.1.0 SETUP LIBS */

libname raw "N:\" ACCESS = READONLY;
libname temp "M:\";

/*0.1.1 GENERATE LIST OF PTS WITH CORRECT DX CODE*/

PROC SQL NOPRINT;
	CREATE TABLE gg_def10 AS
	SELECT *
	FROM 'N:\ccaes103.sas7bdat'
	WHERE (DX1 IN ('123', '12345')) 
	AND (AGE &amp;gt;= (18));
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE gg_def11 AS
	SELECT *
	FROM 'N:\ccaes113.sas7bdat'
	WHERE (DX1 IN ('123', '12345')) 
	AND (AGE &amp;gt;= (18));
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE gg_def12 AS
	SELECT *
	FROM 'N:\ccaes122.sas7bdat'
	WHERE (DX1 IN ('123', '12345')) 
	AND (AGE &amp;gt;= (18));
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE gg_def13 AS
	SELECT *
	FROM 'N:\ccaes130.sas7bdat'
	WHERE (DX1 IN ('123', '12345')) 
	AND (AGE &amp;gt;= (18));
QUIT;

/*Stack the inpatient claims from 2010 - 2013Q3*/

data temp.compiled;
	set gg_def10 gg_def11 gg_def12 gg_def13;

/*0.1.1 CLEAN ELIGIBILITY */

	/*0.1.1.1 COLLAPSE ELIGIBILITY CLAIMS */ 
	
PROC SQL NOPRINT;
	CREATE TABLE elig_10 AS
	SELECT *
	FROM 'N:\ccaet103.sas7bdat'
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled);
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE elig_11 AS
	SELECT *
	FROM 'N:\ccaet113.sas7bdat'
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled);
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE elig_12 AS
	SELECT *
	FROM 'N:\ccaet122.sas7bdat'
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled);
QUIT;

PROC SQL NOPRINT;
	CREATE TABLE elig_13 AS
	SELECT *
	FROM 'N:\ccaet132.sas7bdat'
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled);
QUIT;

data temp.compiled_elig;
	set elig_10 elig_11 elig_12 elig_13;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 06:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420675#M67893</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-13T06:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420677#M67894</link>
      <description>&lt;P&gt;You don't need macro. Just read all of your datasets in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.compiled;
  set raw.ccaes103
        raw.ccaes113
        raw.ccaes122
        raw.ccaes130;
  where dx1 in ('123', '12345') and age &amp;gt;= 18;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 06:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420677#M67894</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-12-13T06:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420678#M67895</link>
      <description>&lt;P&gt;one way to simplify your code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro data_processing(dsn=,file=);
PROC SQL NOPRINT;
	CREATE TABLE &amp;amp;dsn. AS
	SELECT *
	FROM 'N:\&amp;amp;file..sas7bdat'
	WHERE (DX1 IN ('123', '12345')) 
	AND (AGE &amp;gt;= (18));
QUIT;
%mend;


%macro data_processing1(dsn=,file=);
PROC SQL NOPRINT;
	CREATE TABLE &amp;amp;dsn. AS
	SELECT *
	FROM 'N:\&amp;amp;file..sas7bdat'
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled);
QUIT;
%mend;

%data processing(dsn=gg_def10,file=ccaes103);
%data processing(dsn=gg_def11,file=ccaes113);
%data processing(dsn=gg_def12,file=ccaes122);
%data processing(dsn=gg_def13,file=ccaes130);


data temp.compiled;
	set gg_def10 gg_def11 gg_def12 gg_def13;


%data processing1(dsn=elig_10,file=ccaes103);
%data processing1(dsn=elig_11,file=ccaes113);
%data processing1(dsn=elig_12,file=ccaes122);
%data processing1(dsn=elig_13,file=ccaes130);


data temp.compiled_elig;
	set elig_10 elig_11 elig_12 elig_13;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 06:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420678#M67895</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-12-13T06:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420682#M67896</link>
      <description>&lt;P&gt;Thanks! And would that also work for the second half of the program above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So instead of repeating below x4&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;SQL&lt;/SPAN&gt; NOPRINT&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	CREATE &lt;SPAN class="token statement"&gt;TABLE&lt;/SPAN&gt; elig_10 AS
	&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'N:\ccaet103.sas7bdat'&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; ENROLID &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;DISTINCT&lt;/SPAN&gt; ENROLID &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;compiled&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;QUIT&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;.....&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;we would have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;.elig&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; raw&lt;SPAN class="token punctuation"&gt;.ccaet103&lt;/SPAN&gt;
        raw&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;ccaet113
        raw&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;ccaet122
        raw&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;ccaet130&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; enrolid &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; (&lt;SPAN class="token punctuation"&gt;select distinct enrolid from temp.compiled)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 07:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420682#M67896</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-13T07:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420683#M67897</link>
      <description>&lt;P&gt;SELECT DISTINCT ENROLID from temp.compiled is&amp;nbsp; sql statements which does not run in data step&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 07:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420683#M67897</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-12-13T07:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420685#M67898</link>
      <description>I see ... in that case is there a way to make the bottom series of proc SQLs less repetitive? :0&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Dec 2017 07:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420685#M67898</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-13T07:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420687#M67899</link>
      <description>&lt;P&gt;try this,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc sql;
	create table temp.compiled_elig as
	select * from (

		select * from 'N:\ccaet103.sas7bdat'
		union all
		select * from 'N:\ccaet113.sas7bdat'
		union all
		select * from 'N:\ccaet122.sas7bdat'
		union all
		select * from 'N:\ccaet132.sas7bdat'
	)
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled)
	;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 08:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420687#M67899</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-12-13T08:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420688#M67900</link>
      <description>&lt;P&gt;an other alternative to the whole code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	proc sql;
	create table temp.compiled as
	select * from 'N:\ccaet103.sas7bdat'
	union all
	select * from 'N:\ccaet113.sas7bdat'
	union all
	select * from 'N:\ccaet122.sas7bdat'
	union all
	select * from 'N:\ccaet132.sas7bdat'
	;


	create table temp.compiled_elig as
	select * from temp.compiled
	WHERE ENROLID IN (SELECT DISTINCT ENROLID from temp.compiled
					 where (DX1 IN ('123', '12345')) AND (AGE &amp;gt;= (18))
					  )
	;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 08:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420688#M67900</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-12-13T08:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420693#M67901</link>
      <description>&lt;P&gt;I hope that next code will be the most efficient:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1 is identical to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;'s&amp;nbsp;code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.compiled  enrollids(keep=enrollid);
  set raw.ccaes103
        raw.ccaes113
        raw.ccaes122
        raw.ccaes130;
  where dx1 in ('123', '12345') and age &amp;gt;= 18;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Step 2 creates distinct values of ENROLLID:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=enrollids out=enrollids NODUPKEY;&lt;BR /&gt;     by enrollid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Last step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.compiled_elig;
  merge raw.ccaet103 (in=in103)
        raw.ccaet113 (in=in113)
        raw.ccaet122 (in=in122)
        raw.ccaet132 (in=in132)
        enrollids    (in=inids);
  by enrollid;   /* assumes all inputs are sorted by EnrollID */
       if inids and (in103 or in113 or in122 or in132);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 08:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420693#M67901</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-12-13T08:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420705#M67905</link>
      <description>&lt;P&gt;i do have to ask, where did you learn to code like this.&amp;nbsp; I have never in 15 plus years seen anyone use:&lt;/P&gt;&lt;PRE class="language-sas lia-code-sample" data-lia-code-lang="sas" data-lia-code-macro="true"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token keyword" mce-data-marked="1"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="token string" mce-data-marked="1"&gt;'N:\ccaes103.sas7bdat'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You create a libname called raw which points to the datasets and never use them?&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;  from RAW.CCAES103&lt;/PRE&gt;Is how it should look.&amp;nbsp; Anyways&amp;nbsp;&lt;A class="lia-mention-container-editor" href="#" data-lia-user-login="Shmuel" data-lia-user-uid="88384" data-lia-user-macro="true" data-mce-href="#" target="_blank"&gt;@Shmuel&lt;/A&gt;&amp;nbsp;has the correct answer here, concatenate your data&amp;nbsp;&lt;SPAN id="_mce_caret" data-mce-bogus="true" mce-data-marked="1"&gt;&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;/U&gt;&lt;SPAN id="_mce_caret" data-mce-bogus="true"&gt;&lt;SPAN id="_mce_caret" data-mce-bogus="true"&gt; processing removes the repetitiveness in this example and most macro coding examples I have seen.&amp;nbsp; 1 dataset is almost always preferable to multiple ones.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420705#M67905</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-13T09:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420861#M67927</link>
      <description>&lt;P&gt;Thank you! Yea, my coding is horrible :(, but thank you for helping me learn a bit more!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 15:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420861#M67927</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-13T15:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420944#M67933</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;- that style of referencing SAS datasets means you avoid assigning a LIBNAME entirely. I've used it occasionally if I'm just wanting to read a single dataset from a folder that isn't used for anything else. Funny I didn't learn about it until fairly recently myself.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 19:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/420944#M67933</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-12-13T19:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421296#M67959</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Question 1&lt;/U&gt;:&lt;/STRONG&gt; Could I make the code more "user friendly" by allowing a modifiable inputs at the top? e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let inputs = ccaes103 ccaes 113 ccaes122 ccaes130&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then somehow incorporate that to the code later?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can see how we may incorporate this on the dx and age side, e.g. instead of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.compiled  enrollids(keep=enrollid);
  set raw.ccaes103
        raw.ccaes113
        raw.ccaes122
        raw.ccaes130;
  where dx1 in ('123', '12345') and age &amp;gt;= 18;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;we have 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 dx1 = 123, 12345;
%let age_cutoff = 18;

data temp.compiled  enrollids(keep=enrollid);
  set raw.ccaes103
        raw.ccaes113
        raw.ccaes122
        raw.ccaes130;
  where dx1 in &amp;amp;dx1. and age &amp;gt;= &amp;amp;age_cutoff.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Question 2&lt;/U&gt;: &lt;/STRONG&gt;isn't data merge adding all the datasets horizontally? Since these are datasets from different years, should we instead be stacking vertically?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 19:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421296#M67959</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-14T19:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421317#M67961</link>
      <description>&lt;P&gt;When I use the first part of your code, it says&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Column 12 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 13 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 17 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 26 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 13 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 26 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 13 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
ERROR: Column 26 from the first contributor of UNION ALL is not the same type as its
       counterpart from the second.
294          quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any idea what this means? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, this is what I ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		proc sql;
			create table temp.compiled as
			select * from (
				select * from raw.ccaes103 union all
				select * from raw.ccaes113 union all
				select * from raw.ccaes122 union all
				select * from raw.ccaes132)
			where dx1 in ('123', '12345') and age &amp;gt;= 18;
		quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Dec 2017 19:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421317#M67961</guid>
      <dc:creator>cdubs</dc:creator>
      <dc:date>2017-12-14T19:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to wrap repetitive PROC SQLs into a macro? Or otherwise reduce repetitiveness of proc sqls?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421464#M67966</link>
      <description>&lt;P&gt;Question 1) To be honest, I have seen many implementations of macro lists and such like in over 15years, and there is one consistent thing I have found, they never make code more user friendly or modifiable.&amp;nbsp; First there is rarely any documentation to adequately explain the code or parameters, and secondly due to that, those paramter lists can cause fails and bugs of all kinds in the code.&amp;nbsp; For instance a simple step where the name in the list doesn't exist, will you check for this before your code, what about not containing the expected variables, or the right type, correct values etc.&amp;nbsp; The list goes on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question 2) Data merging (joining) is the means of putting data across the page, based on joining variables.&amp;nbsp; Setting data is the method of setting data one under the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally if you want to make your code more robust, put your data into a set library, then you can apply a list to get all of them without knowing up front:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;compiled  enrollids&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;keep&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;enrollid&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; raw&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;ccaes:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;dx&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'123'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'12345'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and age &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;18&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will take all datasets in raw with ccaes prefix.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 09:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-wrap-repetitive-PROC-SQLs-into-a-macro-Or-otherwise/m-p/421464#M67966</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-15T09:12:35Z</dc:date>
    </item>
  </channel>
</rss>

