- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! It works now 😄
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply. I tried DATA WB66.erwzus_1013; SET WB66.erwzusneu; but it doesnt make a new file. Do you know what i could use instead? Or do i have to create an empty file first?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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??
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
Paige Miller