Hi, I've been asked to explain this without any further detail/data/output:
" Arrays werden in einem datastep als Variable in ein workfile geschrieben; wie lese ich diese Variablen in einem neuen datastep wieder ein".
which could translate into something like this I suppose:
" Arrays are written as variables in a workfile in a datastep; how do I read these variables back in a new datastep?".
But I'm not even 100% if I translate it properly, as I never your workfile when talking about a SAS dataset and I've never defined an array in a data step to use it in another one.
Does anyone understand the question better than me and could explain it with simple words or an example?
You can use an ARRAY to CREATE variables. Essentially it is just another example of SAS automatically creating variables the code references that have not been defined previously. Just like if you reference a previously undefined variable in an assignment statement or a FORMAT statement.
To read in the variables you just need to read in the dataset that was created.
But that will not redefine the array. You will have to reference the variables by their actual names not by their position in an array. If you do want to reference them by their position in an array in another data step then you will need include an ARRAY statement in the new data step.
Let's make a dataset using a data step that has an ARRAY.
data have;
array x [10] (1:10);
run;
Now let's read in that dataset in another data step and see what it contains.
data want;
set have;
put (_all_) (=/);
run;
Results
1 data have; 2 array x [10] (1:10); 3 run; NOTE: The data set WORK.HAVE has 1 observations and 10 variables. NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.03 seconds 4 data want; 5 set have; 6 put (_all_) (=/); 7 run; x1=1 x2=2 x3=3 x4=4 x5=5 x6=6 x7=7 x8=8 x9=9 x10=10 NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: The data set WORK.WANT has 1 observations and 10 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
I agree that the question is confusing, and you should never get questions wrong because the question was poorly written.
I think this is the answer:
Even if you have an array in one data step, you would have to define in the code the same array again if that data set were used elsewhere. SAS data sets do not store array information.
You can use an ARRAY to CREATE variables. Essentially it is just another example of SAS automatically creating variables the code references that have not been defined previously. Just like if you reference a previously undefined variable in an assignment statement or a FORMAT statement.
To read in the variables you just need to read in the dataset that was created.
But that will not redefine the array. You will have to reference the variables by their actual names not by their position in an array. If you do want to reference them by their position in an array in another data step then you will need include an ARRAY statement in the new data step.
Let's make a dataset using a data step that has an ARRAY.
data have;
array x [10] (1:10);
run;
Now let's read in that dataset in another data step and see what it contains.
data want;
set have;
put (_all_) (=/);
run;
Results
1 data have; 2 array x [10] (1:10); 3 run; NOTE: The data set WORK.HAVE has 1 observations and 10 variables. NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.03 seconds 4 data want; 5 set have; 6 put (_all_) (=/); 7 run; x1=1 x2=2 x3=3 x4=4 x5=5 x6=6 x7=7 x8=8 x9=9 x10=10 NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: The data set WORK.WANT has 1 observations and 10 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
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!
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.
Ready to level-up your skills? Choose your own adventure.