Please help me to understand how can i get a new column added to set sashelp.yr1001. The new column should be the percentage of total of the column of YR1001.
Below is my code, I am getting the below error and everything is written in log window.
ERROR: Array subscript out of range at line 81 column 43.
Code -
proc means data=sashelp.yr1001 noprint;
output out=abc (drop= _ : ) sum= sum_1 - sum_504;
run;
data ab1;
set sashelp.yr1001;
if _n_ = 1 then set abc;
array z(*) s0:;
do i = 1 to dim(z);
if z(i)=. then z(i)=1;
end;
array x(*) p1 - p504;
array y(*) sum:;
do i = 1 to dim(x);
if x(i)=. then x(i)=(y(i)/z(i))/100;
end;
run;
Hello,
There are only 503 columns in sashelp.yr1001 whose name begins with "S0" so your array z has one element
less than the others.
no, there are 505 variable in YR1001 out of which 504 start with 'S00'.
Post test data in the form of a datastep using the code window (it is the {i} above post area), only need a few rows:
There is no other way we can infer what you are working with. One of the three arrays has not enough elements, most likely one is y as the other two are looped by dim().
if i change the array size from 504 to 503 code is working fine. But when i go through the properties of Yr1001 there are 505 variables in it. Is something i am missing.
Name: | YR1001 |
Description: | M-competition 1001 Series, Annual |
Type: | Table |
Location: | SASHELP.YR1001 |
Rows: | 126 |
Columns: | 505 |
Date created: | Aug 10, 2017, 7:35:46 AM |
Date modified: | Aug 10, 2017, 7:35:46 AM |
proc sql;
SELECT NAME
FROM dictionary.columns
WHERE LIBNAME="SASHELP" AND MEMNAME="YR1001"
AND NAME NOT LIKE "S0%";
;
quit;
SAS Output
Column Name |
---|
T |
S1000 |
Can I ask, how do you know this, there is no YR1001 dataset in SASHELP on my install? Hence why I keep asking for test data.
There is such a dataset on my SAS install. I just discovered its existence so i cannot tell you more than that.
Edit : Sas 9.4 / windows 7
I am using SAS Studio and SAS University Edition, in libraries ,in both the option this YR1001 is there.
Yep, not on mine. I think this clearly shows why test data should be screen one when posting questions in future, I will push this as suggestion for the forums.
Looks like this is solved now -- but just to explain why some people have YR1001 and others don't. yr1001.sas7bdat is distributed with SAS/ETS, and at least parts of ETS are included in SAS University Edition.
@ChrisHemedinger and @vishalrajpoot3: I don't think this is solved yet.
The initial proc means was:
proc means data=sashelp.yr1001 noprint;
output out=abc (drop= _ : ) sum= sum_1 - sum_504;
run;
That will create sums for T and s0001--s0996. I don't think that is what was wanted.
The following, I think, does accomplish the task correctly:
proc means data=sashelp.yr1001 (drop=t) noprint;
output out=abc sum= xsum_1 - xsum_504;
run;
data ab1 (drop=xsum: i);
set sashelp.yr1001;
if _n_ = 1 then set abc;
array z(*) xsum:;
do i = 1 to dim(z);
if missing(z(i)) then z(i)=1;
end;
array x(*) p1 - p504;
array y(*) s:;
do i = 1 to dim(x);
if x(i)=. then x(i)=(y(i)/z(i))/100;
end;
run;
Art, CEO, AnalystFinder.com
Thanks
When you assigning 1 for missing value, why this is not showing in output data set.
below is the code I came with as solution-
proc means data=sashelp.yr1001 noprint;
output out=abc (drop= _ : ) sum= add_1 - add_504;
run;
data ab1 (drop=add:);
set sashelp.yr1001;
if _n_ = 1 then set abc;
array z(*) S:;
do i = 1 to dim(z);
if z(i)=. then z(i)=1;
end;
array x(*) p1 - p504;
array y(*) add_:;
do i = 1 to dim(x);
if x(i)=. then x(i)=(z(i)/y(i))*100;
end;
run;
The output provided tells me very little. There may be 505 columns, but what are those columns. Post test data in the form of a datastep:
there is 505 column and only first column is 'T' and rest 504 starts with 'S0'.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.