BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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

 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 347 views
  • 0 likes
  • 3 in conversation