DATA Step, Macro, Functions and more

Controlling Variable Suffix by Creating New Variables with an Array

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Controlling Variable Suffix by Creating New Variables with an Array

[ Edited ]

Hi,

 

I'm trying to create new variables with an array statement that contain suffixes that match from a previously referenced array statement. This is my code:

DATA BLAH_F7;
	SET BLAH_F;
	ARRAY A[0:100]F_0--F_100;
	ARRAY P_[0:100]P_0--P_100;
		DO I=0 TO 100;
		P_(I)=A(I)/F_TOTAL;
	END;
	DROP I;
RUN;

When I run this code, the array creates variables P_1 to P_101 instead of from P_0 to P_100, which is what I want (as I am trying to match to the F_0 to F_100 variables). Anyone have any suggestions? If this isn't possible using an array statement, I'd still be interested in hearing the simplest way to change these P_1 to P_101 variables to P_0 to P_100.

 

Thanks.


Accepted Solutions
Solution
‎07-26-2016 11:44 AM
Super User
Posts: 19,770

Re: Controlling Variable Suffix by Creating New Variables with an Array

Posted in reply to kevinmc87

Try the following, though I would have thought that P0-P100 would work. 

 

Array p_(0:100) p0 p1-p100;

 

View solution in original post


All Replies
Solution
‎07-26-2016 11:44 AM
Super User
Posts: 19,770

Re: Controlling Variable Suffix by Creating New Variables with an Array

Posted in reply to kevinmc87

Try the following, though I would have thought that P0-P100 would work. 

 

Array p_(0:100) p0 p1-p100;

 

Contributor
Posts: 29

Re: Controlling Variable Suffix by Creating New Variables with an Array

Thanks, this solution works. I guess P_0 needs to be explicitly stated since this is an array statement that isn't referencing any previously exisiting variables? I'm a little confused by why this works:

 

Array p_(0:100) p0 p1-p100;

 

but this doesn't work:

 

Array p_(0:100) p0-p100;

 

Thanks for your help!

Super User
Posts: 5,498

Re: Controlling Variable Suffix by Creating New Variables with an Array

Posted in reply to kevinmc87

Both of those should work. 

 

The piece that doesn't work is the double dash.  For SAS to interpret the double dash properly, the variables must already exist and cannot be created by the ARRAY statement.

Contributor
Posts: 29

Re: Controlling Variable Suffix by Creating New Variables with an Array

Posted in reply to Astounding

Thanks, Astouding. I did not realize this.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 226 views
  • 1 like
  • 3 in conversation