<?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: Dynamic Creation of dictionary keys in CASL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Creation-of-dictionary-keys-in-CASL/m-p/590692#M169109</link>
    <description>&lt;P&gt;Reading the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=caslpg&amp;amp;docsetTarget=n0th2eeb2wsa24n1ptps7vu9plb7.htm&amp;amp;docsetVersion=3.4&amp;amp;locale=en" target="_self"&gt;documentation&lt;/A&gt;&amp;nbsp;both the dot and bracket notation should work. I don't understand how the syntax for the dot notation would need to look like but it appears using brackets returns the result you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
  count = {"one", "two", "three"};
  do x over count;
    print x;
    temp_dict[x] = x;
  end;
  print temp_dict;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;one
two
three
{one=one,two=two,three=three}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Sep 2019 03:26:02 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-09-22T03:26:02Z</dc:date>
    <item>
      <title>Dynamic Creation of dictionary keys in CASL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Creation-of-dictionary-keys-in-CASL/m-p/590248#M169032</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to dynamically create a dictionary in the CASL. In this case I will not know the dictionary keys until I am iterating through an array creating the dictionary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is example code of what I am trying to do with current output and what I want as an output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc cas;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; count = {"one", "two", "three"};&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; do x over count;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print x;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temp_dic.x = "hi there";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; print temp_dic;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current output:&lt;/P&gt;&lt;DIV class="sasSource"&gt;one&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;two&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;three&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;{x=hi there}&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Wanted output:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;one&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;two&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;three&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;{one = "hi there", two="hi there", three = "hi there"}&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Obviously this is a simplified example, but the thing that I am trying to find out is to evaluate x and use as a dictionary key.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;It seems odd that CAS evaluates x differently in side the loop. I also tried casting x as a string, and am all out of ideas.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Is what I am trying to do possible? or am I unable to resolve x inside the loop as a dictionary key?&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Thanks!&lt;/DIV&gt;</description>
      <pubDate>Fri, 20 Sep 2019 02:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Creation-of-dictionary-keys-in-CASL/m-p/590248#M169032</guid>
      <dc:creator>buncket</dc:creator>
      <dc:date>2019-09-20T02:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Creation of dictionary keys in CASL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Creation-of-dictionary-keys-in-CASL/m-p/590692#M169109</link>
      <description>&lt;P&gt;Reading the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=caslpg&amp;amp;docsetTarget=n0th2eeb2wsa24n1ptps7vu9plb7.htm&amp;amp;docsetVersion=3.4&amp;amp;locale=en" target="_self"&gt;documentation&lt;/A&gt;&amp;nbsp;both the dot and bracket notation should work. I don't understand how the syntax for the dot notation would need to look like but it appears using brackets returns the result you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
  count = {"one", "two", "three"};
  do x over count;
    print x;
    temp_dict[x] = x;
  end;
  print temp_dict;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;one
two
three
{one=one,two=two,three=three}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2019 03:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Creation-of-dictionary-keys-in-CASL/m-p/590692#M169109</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-22T03:26:02Z</dc:date>
    </item>
  </channel>
</rss>

