DATA Step, Macro, Functions and more

Element name in a data step array

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Element name in a data step array

I would like to obtain the actual element name in a data step array as opposed to the value of that column. Is there any way to obtain the value? Example below;

data _null_;

     array test {1} helloworld;

    

     do j=1 to 1;

          call symput('name', test{1} );

     end;

run;

%put &name; /*I would like the name value to be helloworld */


Accepted Solutions
Solution
‎05-11-2012 10:41 AM
Super User
Posts: 17,958

Re: Element name in a data step array

VNAME function

data _null_;

     array test {1} helloworld;

   

     do j=1 to 1;

          call symput('name', vname(test{1}) );

     end;

run;

%put &name; /*I would like the name value to be helloworld */

View solution in original post


All Replies
Solution
‎05-11-2012 10:41 AM
Super User
Posts: 17,958

Re: Element name in a data step array

VNAME function

data _null_;

     array test {1} helloworld;

   

     do j=1 to 1;

          call symput('name', vname(test{1}) );

     end;

run;

%put &name; /*I would like the name value to be helloworld */

PROC Star
Posts: 7,366

Re: Element name in a data step array

data _null_;

     array test{1} $20. ("helloworld");

   

     do j=1 to 1;

          call symput('name', test{1} );

     end;

run;

%put &name; /*I would like the name value to be helloworld */

Contributor
Posts: 28

Re: Element name in a data step array

Wow you guys are quick!!!
Reeza works exactly as expected even with multiple array values.
Arthur yours works as well it just was not as straight forward how to add multiple array values;

data _null_;

     array test {2} hello world;

  

     do j=1 to 2;

          call symput('name', vname(test{j}) );

     end;

run;

%put &name; /*Puts world */

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 195 views
  • 3 likes
  • 3 in conversation