<?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 create dynamic suffix on a numbered variable list? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295480#M61750</link>
    <description>&lt;P&gt;You're most of the way there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that SQL must perform a numeric to character conversion, to feed the numeric value into &amp;amp;COMMACOUNT.&amp;nbsp; This conversion generates leading blanks in the value of &amp;amp;COMMACOUNT.&amp;nbsp; One simple way to remove those leading blanks would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%lead commacount = &amp;amp;commacount;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would go between the SQL and the DATA step, and should take care of the problem.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2016 12:33:58 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-08-31T12:33:58Z</dc:date>
    <item>
      <title>How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295471#M61743</link>
      <description>&lt;P&gt;Hello, I am just learning SAS and so far have not found a way to dynamically create variables based on a count of a character in a string. I am parsing out a string from Active Directory (for example: CN=N123456,OU=Users,OU=Admins,DC=D01,DC=com). I have successfully created collumns for each item following a comma, but it is not dynamic. I have been running a proc sql query&amp;nbsp;to find the Active Directory string with the most commas, and then creating an array based on that number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the file I am currently working with, the largest number of commas is 7, so I need 8 columns. I have been creating varialbes like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;array parsed_vars(8)$50 VAR1-VAR8;&lt;/PRE&gt;&lt;P&gt;I want to store the number of collumns I need based on my comma count and pass that into the array, something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;array parsed_vars(nmbrvar)$50 VAR1-VAR||nmbrvar;&lt;/PRE&gt;&lt;P&gt;The log shows this:&lt;/P&gt;&lt;P&gt;ERROR: Missing numeric suffix on a numbered variable list (OU1-OU).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this? I am working in SAS Enterprise Guide 5.1.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 11:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295471#M61743</guid>
      <dc:creator>gsouther</dc:creator>
      <dc:date>2016-08-31T11:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295472#M61744</link>
      <description>&lt;P&gt;In your proc sql, use the into: clause to store your result into a macro variable.&lt;/P&gt;
&lt;P&gt;Like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select max(count) into : maxcount from ....;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use maxcount in further coding:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data something;
set have;
array vars {&amp;amp;maxcount} var1-var&amp;amp;maxcount;
.....
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 11:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295472#M61744</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-31T11:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295476#M61746</link>
      <description>&lt;P&gt;Thanks for the response! I was missing the into: clause. It&amp;nbsp;seems to be getting&amp;nbsp;a little further, but&amp;nbsp;I am still getting the error about missing the numeric suffix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select max(count(distinguishedname,","))+1 into : commacount from have;
quit;


data something;
set have;
array parsed_vars{&amp;amp;commacount}$50 VAR1-VAR&amp;amp;commacount;
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;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28         data something;
29         set have;
30         array parsed_vars{&amp;amp;commacount}$50 VAR1-VAR&amp;amp;commacount;
NOTE: Line generated by the macro variable "COMMACOUNT".
30         VAR       9
                    _
                    22
                    200
ERROR: Missing numeric suffix on a numbered variable list (VAR1-VAR).
ERROR: Too few variables defined for the dimension(s) specified for the array parsed_vars.
ERROR 22-322: Syntax error, expecting one of the following: a name, (, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 12:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295476#M61746</guid>
      <dc:creator>gsouther</dc:creator>
      <dc:date>2016-08-31T12:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295478#M61748</link>
      <description>&lt;P&gt;Personally I would normalise your data, i.e. put each data item into a separate observation. &amp;nbsp;If necessary you could then transpose them up or work with it as is.&lt;/P&gt;
&lt;PRE&gt;data temp;
  str="CN=N123456,OU=Users,OU=Admins,DC=D01,DC=com";
  do i=1 to countw(str,",");
    word=scan(str,i,",");
    output;
  end;
run;
proc transpose data=temp out=t_temp prefix=word;
  var word;
  id i;
  idlabel i;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 12:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295478#M61748</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-31T12:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295480#M61750</link>
      <description>&lt;P&gt;You're most of the way there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that SQL must perform a numeric to character conversion, to feed the numeric value into &amp;amp;COMMACOUNT.&amp;nbsp; This conversion generates leading blanks in the value of &amp;amp;COMMACOUNT.&amp;nbsp; One simple way to remove those leading blanks would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%lead commacount = &amp;amp;commacount;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would go between the SQL and the DATA step, and should take care of the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 12:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295480#M61750</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-31T12:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295486#M61753</link>
      <description>&lt;P&gt;Some autocompletion seems to have played a trick on you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%lead commacount = &amp;amp;commacount;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let commacount = &amp;amp;commacount;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 12:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295486#M61753</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-31T12:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295488#M61755</link>
      <description>&lt;P&gt;That's just my brain trying to function before the first cup of coffee.&amp;nbsp; Absolutely, use %LET not %LEAD.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 13:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295488#M61755</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-31T13:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295507#M61760</link>
      <description>&lt;P&gt;Thanks for the help! I have it working now with the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select max(count(distinguishedname,","))+1 into : commacount from have;
quit;

%let commacount = &amp;amp;commacount;

data something;
set have;
array parsed_vars{&amp;amp;commacount}$50 VAR1-VAR&amp;amp;commacount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295507#M61760</guid>
      <dc:creator>gsouther</dc:creator>
      <dc:date>2016-08-31T14:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295515#M61766</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;HAVE

Up to 40 obs WORK.HAVE total obs=10

Obs    CMADLM

  1    aaaa,aaaa,aaaa,aaaa,1stwrd
  2    aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa
  3    aaaa,aaaa,aaaa
  4    aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa
  5    aaaa,aaaa
  6    aaaa,aaaa,aaaa,aaaa
  7    aaaa,aaaa
  8    aaaa,aaaa,aaaa,aaaa,aaaa,aaaa
  9    aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa
 10    aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa,aaaa

WANT


Up to 40 obs WORK.TEMP total obs=10

Obs     V1      V2      V3      V4       V5       V6      V7      V8      V9

  1    aaaa    aaaa    aaaa    aaaa    1stwrd
  2    aaaa    aaaa    aaaa    aaaa    aaaa      aaaa    aaaa    aaaa    aaaa
  3    aaaa    aaaa    aaaa
  4    aaaa    aaaa    aaaa    aaaa    aaaa      aaaa    aaaa    aaaa    aaaa
  5    aaaa    aaaa
  6    aaaa    aaaa    aaaa    aaaa
  7    aaaa    aaaa
  8    aaaa    aaaa    aaaa    aaaa    aaaa      aaaa
  9    aaaa    aaaa    aaaa    aaaa    aaaa      aaaa    aaaa
 10    aaaa    aaaa    aaaa    aaaa    aaaa      aaaa    aaaa    aaaa    aaaa


* The maximum size the array can be is 656 because 656*50=32800;
* 50 was mentioned in the instructions - but could set higher 4096;
* without performance penaly?;

data interim;
  retain cmacnt 0;
  set have(in=have);
  array vars[*] $50 v1-v656;
  do cma=1 to (countc(cmadlm,',')+1);
     vars[cma]=scan(cmadlm,cma,',');
  end;
  if cmacnt &amp;lt; cma-1 then cmacnt=cma-1;
  call symputx('cmacnt',put(cmacnt,4.));
run;quit;

data temp;
  set interim(keep=v1-v&amp;amp;cmacnt);
run;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295515#M61766</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-08-31T14:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295516#M61767</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Code to create have

data have;
 length cmadlm $500;
 retain cmadlm '1stwrd';
 do str=1 to 10;
    too=10*uniform(57371);
    do cma=1 to too;
      cmadlm=catx(',','aaaa',cmadlm);
    end;
    output;
    cmadlm=' ';
 end;
 keep cmadlm;
run;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295516#M61767</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-08-31T14:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dynamic suffix on a numbered variable list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295520#M61769</link>
      <description>&lt;P&gt;Correction I don't know what I was thinking but 656 is not large enough, it assumes the string has at least 50 bytes between commas.&lt;/P&gt;&lt;P&gt;Oh well, I thinl 16384 is the max.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dynamic-suffix-on-a-numbered-variable-list/m-p/295520#M61769</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-08-31T14:32:51Z</dc:date>
    </item>
  </channel>
</rss>

