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.
Try the following, though I would have thought that P0-P100 would work.
Array p_(0:100) p0 p1-p100;
Try the following, though I would have thought that P0-P100 would work.
Array p_(0:100) p0 p1-p100;
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!
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.
Thanks, Astouding. I did not realize this.
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.
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.