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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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

 

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

 

kevinmc87
Obsidian | Level 7

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!

Astounding
PROC Star

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.

kevinmc87
Obsidian | Level 7

Thanks, Astouding. I did not realize this.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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