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

This came up in another question, and would like to get some guidance, otherwise I might add this as a feature request.  The question was, having a set of non-standard variables names, how to move these to an enumerated list, like sq_1, sq_2 etc.

There are a number of ways to do it, however I was wondering why the below does not work - it states that sq_1... is not found:

data have;
  vara=1; varxyz=2; abc=4;
run;

data want (keep=sq_:);
  set have;
  array sq_{*} vara--abc;
run;

However the following, where I also create an array, does get retained:

data have;
  vara=1; varxyz=2; abc=4;
run;

data want (keep=sq_:);
  set have;
  array aq_{*} vara--abc;
  array sq_{3} 8.;
  do i=1 to 3;
    sq_{i}=aq_{i};
  end;
run;

It seems like setting an array with a list of variables defaults it to _temporary_, which I suppose makes sense, but there are also times when you may want to keep those variables, so maybe an option _nottemporary_.  But I couldn't find anything like that.  Seems a bit of a faff to have to code around it.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Maybe, back then when the array feature was designed and memory was scarce, the developers were hesitant to provide an option which would create redundancy by duplicating variables (although possible in principle). So, they came up with the pointer idea.

View solution in original post

8 REPLIES 8
FreelanceReinh
Jade | Level 19

Please see my explanation in the original thread.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Yes, lets carry it on here rather than jumping someone else's post.  I do understand that that is the default action, if the variables exist then a pointer to them is created rather than a variable.  Even so, personally I would like to see an option that these actually be created, it is something that comes up a fair bit - going from list of variables to array processing, even if only to simplify coding.

FreelanceReinh
Jade | Level 19

Maybe, back then when the array feature was designed and memory was scarce, the developers were hesitant to provide an option which would create redundancy by duplicating variables (although possible in principle). So, they came up with the pointer idea.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thanks, suppose I will have to stick with the faffing about then 🐵

data_null__
Jade | Level 19

You keep saying that which makes me think you still don't understand data step arrays and what.. 

 

array sq_[*] list-of-variables-names;

 

Does and perhaps more importantly does not do.

 

Please read the links from my previous reply.

Astounding
PROC Star

Just for the record, some renames of lists are supported:

 

rename a1-a3 = sq_1 - sq_3;

 

But some are not:

 

rename var1--abc = sq_1 - sq_3;

 

That may be another way to look at the feature you would like to have.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thanks.  Yes its another way to look at it.  I presume the second doesn't work as it doesn't know how many in the first list of variables there are.

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
  • 8 replies
  • 974 views
  • 1 like
  • 4 in conversation