<?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 do I create 'dynamic' sql in amarco? SAS 9 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333711#M272130</link>
    <description>If the collection of columns is mixed types (chars and nums) the --range of names has a very convenient extension&lt;BR /&gt;&lt;BR /&gt;AB1_AccountID -character- AB3_Address&lt;BR /&gt;AB1_AccountID -numeric- AB3_Address&lt;BR /&gt;This extension of the -- range segregate columns by data type.&lt;BR /&gt;It does not matter if the "end-points" of the name range are of the "wrong" type - they would be ignored just as wrong datatypes within the range would be ignored.&lt;BR /&gt;</description>
    <pubDate>Fri, 17 Feb 2017 09:21:32 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2017-02-17T09:21:32Z</dc:date>
    <item>
      <title>How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333211#M272127</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to dynamically create tables,&amp;nbsp;using a macro, from a larger table based on the column names (so I don't have to do a&amp;nbsp; 40&amp;nbsp; select union) . the final goal is a crosstab table. &amp;nbsp;The column names in the source table&amp;nbsp;are like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AB1_AccountID &amp;nbsp;AB1_Name &amp;nbsp; AB1_Address &amp;nbsp;AB2_AccountID &amp;nbsp;AB2_Name &amp;nbsp;&amp;nbsp;&amp;nbsp; AB2_Address&amp;nbsp; etc. ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;1234&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Besty Ross 123 MainSt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 34567&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Frank N Stein&amp;nbsp;&amp;nbsp;&amp;nbsp;PO BOX 66&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like a table of the AB1 data, the AB2 data etc. that looks &amp;nbsp;like&lt;/P&gt;&lt;P&gt;Table AB1_Recs&lt;/P&gt;&lt;P&gt;AB1_AccountID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AB1_Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AB1_Address&lt;/P&gt;&lt;P&gt;12345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Besty Ross&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123 Main St&lt;/P&gt;&lt;P&gt;34567&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Frank N Stein&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PO Box 66&lt;/P&gt;&lt;P&gt;.etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I was trying to use a macro to create the individual datasets :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro Make40Tabless;&lt;/P&gt;&lt;P&gt;%do j=1 %to 40;&lt;/P&gt;&lt;P&gt;%LET brnum=BR&amp;amp;j;&lt;/P&gt;&lt;P&gt;　　&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table yaddayadda_ab1 as&lt;/P&gt;&lt;P&gt;select "&amp;amp;brnum"||_AccountID from yaddayadda_wrk; run;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%Make40Tables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried all sorts of variations on having the variables in " and not, and the closest I can get is an error saying the column names BR1, _AccountID are not found in the dataset. What am I doing wrong? Is this really the dorkiest way to do this or is there a better way? I am new to SAS programming, am I&amp;nbsp;making this harder than it has to be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I *might* could do without the individual datasets if it's easier.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cat&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 22:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333211#M272127</guid>
      <dc:creator>Cathryn</dc:creator>
      <dc:date>2017-02-15T22:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333231#M272128</link>
      <description>&lt;P&gt;Your answer could be answered more easily if we knew what your ultimate crosstabs have to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that said, you can probably get by a lot easier if you make the file a long rather than a wide file. With a long file you can probably run just one proc freq, using AB as a by variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all of your variables are character variables, you could do something like the following to make the file long:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data need (keep=AB AccountID Account_Name Account_Address);
  set have;
  array stuff(*) AB1_AccountID--AB40_Address;
  do i=0 to 39;
    if not missing(stuff(i*3+1)) then do;
      AB=i+1;
      AccountID=stuff(i*3+1);
      Account_Name=stuff(i*3+2);
      Account_Address=stuff(i*3+3);
      output;
    end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 23:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333231#M272128</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-15T23:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333250#M272129</link>
      <description>&lt;P&gt;This is a good candidate for using PROC TRANSPOSE. Let's make some dummy data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  length
    AB1_AccountID $10
    AB1_Name      $30
    AB1_Address   $100
    AB2_AccountID $10
    AB2_Name      $30
    AB2_Address   $100
    AB3_AccountID $10
    AB3_Name      $30
    AB3_Address   $100
  ;
  infile cards dsd dlm='|' flowover ;
  input AB1_AccountID -- AB3_Address ;
cards;
1234|Besty Ross|123 Main St
34567|Frank N Stein|PO BOX 66
567|Jane Doe|3 North Broadway
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So transpose it once to convert the values into one long column.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=tall ;
  var AB1_AccountID -- AB3_Address ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The edit the result and pull the metadata out of the variable names. &amp;nbsp;This code is assuming the names all start ABnn_ where nn could be 1 or more digits. So can convert the NN into the new field RECNO and remove it from the _NAME_ field generated by PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  set tall ;
  recno = input(substr(scan(_name_,1,'_'),3),10.);
  _name_ = substr(_name_,length(scan(_name_,1,'_'))+2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now resort the data and call PROC TRANSPOSE again.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort ;
  by recno _name_;
run;
proc transpose data=tall out=want (drop=_:);
  by recno ;
  id _name_;
  var col1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2017 01:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333250#M272129</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-16T01:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333711#M272130</link>
      <description>If the collection of columns is mixed types (chars and nums) the --range of names has a very convenient extension&lt;BR /&gt;&lt;BR /&gt;AB1_AccountID -character- AB3_Address&lt;BR /&gt;AB1_AccountID -numeric- AB3_Address&lt;BR /&gt;This extension of the -- range segregate columns by data type.&lt;BR /&gt;It does not matter if the "end-points" of the name range are of the "wrong" type - they would be ignored just as wrong datatypes within the range would be ignored.&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Feb 2017 09:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/333711#M272130</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-17T09:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/335035#M272131</link>
      <description>Hello, First many apologies for the response delay, my hair was afire with some other issues. Secondly, thank you for the responses. I am going to try both the solutions but wanted to give a bit more info. The incoming data is a flat file that has a main person (with similar info, plus transaction info) and then each AB associated with the transaction so:&lt;BR /&gt;Main Person Account ID, Main Person Name, Main Person Address, ...AB1 AccountID, AB1_Name...-AB40 AccountID...I need to transpose the file to process each AB group and then un-transpose and rebuild the file as input so i can then recreate file on output .I will give these solutions a whirl and let you know. Thanks Cat</description>
      <pubDate>Wed, 22 Feb 2017 16:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/335035#M272131</guid>
      <dc:creator>Cathryn</dc:creator>
      <dc:date>2017-02-22T16:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create 'dynamic' sql in amarco? SAS 9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/351578#M272132</link>
      <description>Hi Cat&lt;BR /&gt;Did you build a solution?</description>
      <pubDate>Thu, 20 Apr 2017 08:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-dynamic-sql-in-amarco-SAS-9/m-p/351578#M272132</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-04-20T08:39:42Z</dc:date>
    </item>
  </channel>
</rss>

