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

I'm looking for a way to get the contents/variables of array.
For example

data work.chars;
 char1 = "aa";
 char2 = "bb";
 output;
run;

data work.test2;
 length _GETNAMES $40. ;
 set work.chars;
 array ch _CHARACTER_;
 do over ch;
       _GETNAMES = vname(ch);
         if _GETNAMES ^= "_GETNAMES" then put _GETNAMES;
 end;
run;

array.JPG

 

We know that array "ch" has variable cha1 char2 inside, 

Is there a way to get it with 1 time? 

The result is "cha1 char2" or "cha1,char2".

So as to allow “vlabel” function to get the content of label  in the variable.

I'm searching a function or way to catch contents of array.

 

Sincerely.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You can build the list this way:

 

data work.chars;
 char1 = "aa";
 char2 = "bb";
 output;
run;

data work.test2;
if 0 then set work.chars;
array ch _CHARACTER_; /* Declared before creating variable _GETNAMES */
length _GETNAMES $40 ;
do i = 1 to dim(ch);
   _GETNAMES = catx(", ", _GETNAMES, vname(ch{i}));
    end;
put _GETNAMES;
output;
stop;
run;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

You can build the list this way:

 

data work.chars;
 char1 = "aa";
 char2 = "bb";
 output;
run;

data work.test2;
if 0 then set work.chars;
array ch _CHARACTER_; /* Declared before creating variable _GETNAMES */
length _GETNAMES $40 ;
do i = 1 to dim(ch);
   _GETNAMES = catx(", ", _GETNAMES, vname(ch{i}));
    end;
put _GETNAMES;
output;
stop;
run;
PG
t_ar_taat
Quartz | Level 8

Hi,PGStats

It works well.

Thank you so much!

array_ans.JPG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 1109 views
  • 1 like
  • 2 in conversation