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

I have several variables ordered in SAS such as this: var_10_1, var_10_2, var_1_1, var_1_2, var_2_1, var_2_2.

 

If I use an array statement such as the following, what position would these variables be in?

 

array var (1:10) var_:;

 

I'm thinking they are character sorted so var_10_1 is before var_1_1, but the order by which they are in the dataset (which is the same in this circumstance) could also be an option. If the latter is the case I can use a retain to re-order them, but if the former is the case I'll have to come up with a different solution to put var_1 before var_10.

 

Thanks for you help!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The order in the array is the order in which the variables were first created.  You can check that by running a PROC CONTENTS.  One of the pieces of output is the order of the variables.  You can even shorten the output to refer to just the variables of interest:

 

proc contents data=have (keep=var_: );

run;

 

And as was mentioned, if you are processing the variables within a DATA step, using a DO loop and an array, the VNAME function will tell you the variable name for the current array element.

View solution in original post

2 REPLIES 2
Reeza
Super User

Use VNAME to test it. 

 

Given your indexes perhasps you want a two dimensional array making it easier to know which you’re referencing?

Astounding
PROC Star

The order in the array is the order in which the variables were first created.  You can check that by running a PROC CONTENTS.  One of the pieces of output is the order of the variables.  You can even shorten the output to refer to just the variables of interest:

 

proc contents data=have (keep=var_: );

run;

 

And as was mentioned, if you are processing the variables within a DATA step, using a DO loop and an array, the VNAME function will tell you the variable name for the current array element.

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
  • 2 replies
  • 704 views
  • 4 likes
  • 3 in conversation