BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buncket
Calcite | Level 5

Hi everyone,

 

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.

 

Below is example code of what I am trying to do with current output and what I want as an output.

 

proc cas;

    count = {"one", "two", "three"};

    do x over count;

        print x;

        temp_dic.x = "hi there";

    end;

 

    print temp_dic;

run;

 

Current output:

one
two
three
{x=hi there}
 
Wanted output:
one
two
three
{one = "hi there", two="hi there", three = "hi there"}
 
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.
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. 
 
Is what I am trying to do possible? or am I unable to resolve x inside the loop as a dictionary key?
 
Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Reading the documentation 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.

proc cas;
  count = {"one", "two", "three"};
  do x over count;
    print x;
    temp_dict[x] = x;
  end;
  print temp_dict;
run;quit;
one
two
three
{one=one,two=two,three=three}

 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

Reading the documentation 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.

proc cas;
  count = {"one", "two", "three"};
  do x over count;
    print x;
    temp_dict[x] = x;
  end;
  print temp_dict;
run;quit;
one
two
three
{one=one,two=two,three=three}

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 840 views
  • 1 like
  • 2 in conversation