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}

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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