We have the following problem. We want SAS to put the same value that is inside the last beruf variable that contains info into the next one if the control variables Übergänge and BERUFG_A_1 match. There are beruf1 to beruf 21 so 21 variables. If we use this code it says array subscript out of range.
LIBNAME WB66 'D:\WB66';
RUN;
DATA WB66.erwzus_1013; SET WB66.erwzus_1013;
array beruf (1:21) $ beruf1-character-beruf21;
do i = 1 to dim(beruf);
if Übergänge = 2 and BERUFG_A_1=1 and i = index then beruf{i} = beruf{i-1};
end;
RUN;
The messages in the log should show the value of I used when the error happened.
It should be happening when I=1 since you have beruf{i-1} in your code.
Change your DO loop starting from 1 to 2 if you want to do that.
do i = 2 to dim(beruf);
The messages in the log should show the value of I used when the error happened.
It should be happening when I=1 since you have beruf{i-1} in your code.
Change your DO loop starting from 1 to 2 if you want to do that.
do i = 2 to dim(beruf);
Thank you! It works now 😄
Please post the complete log using "insert code", also note that "DATA WB66.erwzus_1013; SET WB66.erwzus_1013;" is always a very bad idea, if something went wrong in the step, you have to re-create WB66.erwzus_1013.
I tried DATA WB66.erwzus_1013; SET WB66.erwzusneu; but it doesnt make a new file.
Was there already a existing file named WB66.erwzus_1013??
@Gablz wrote:
Yes there was and it will always get replaced
That's what your code is telling SAS to do. If you want a new file to be created, you need to use a file name that doesn't exist. For example:
DATA WB66.erwzus_1013new;
SET WB66.erwzusneu;
@Gablz wrote:
Maybe thats a little bit confusing but there already is WB66.erwzus_1013 with information that i want to work with and i want the program to make a new file and he should put everything that i change into that file like a copy but with the changes
The names of dataset(s) listed in the DATA statement are the target names. The names of dataset(s) listed in the SET statement are the source datasets.
The comment that triggered the discussion was that you should be very careful about using the same name in both places because if there is a problem then your source dataset might be lost.
Instead get in the habit of making a new dataset to and only read from the original dataset. The new dataset will have all of the data from the old datasets with any changes made to it in this data step.
data new;
set old;
*** more statements that manipulate the data ** ;
run;
@Gablz wrote:
But i also want the program to use Data from an existing file so i want him to take the information out of WB66.erwzus_1013. If i do it that way SAS tells me the file doesnt exist
I think this is what you want
DATA WB66.erwzus_1013new;
SET WB66.erwzus_1013;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.