Refer a variable

Reply
Contributor
Posts: 35

Refer a variable

Hi

 

I would like to know all the possible ways to refer a varaible created in one data step to in an another datastep.

 

Thanks

Neal.

Trusted Advisor
Posts: 1,919

Re: Refer a variable

Posted in reply to saslovethemost

Look up the data step commands MERGE and UPDATE.

 

Also, this is possible in PROC SQL.

Contributor
Posts: 35

Re: Refer a variable

Posted in reply to PaigeMiller

Sorry was not specific enough I think. How to use the value that is been created in one data step in another datastep.

Super User
Posts: 19,815

Re: Refer a variable

Posted in reply to saslovethemost
What are you trying to do?
Trusted Advisor
Posts: 1,919

Re: Refer a variable

Posted in reply to saslovethemost

saslovethemost wrote:

Sorry was not specific enough I think. How to use the value that is been created in one data step in another datastep.


I already answered this.

 

I said:

 

Look up the data step commands MERGE and UPDATE.

 

Also, this is possible in PROC SQL.

Respected Advisor
Posts: 4,925

Re: Refer a variable

[ Edited ]
Posted in reply to saslovethemost

There are two kinds of variables in SAS : dataset variables and macro variables.

 

  • Dataset variables reside within a dataset. You don't have access to them in another data step unless you refer to the dataset in a SET, MERGE, UPDATE or MODIFY statement.
  • Macro variables are handled by the SAS interpreter. They are simple name=string pairs that can be reused anywhere in a SAS session. The interpreter compiles program blocks ( DATA ... RUN; or PROC ... RUN; ) at a time. So if you give a value to a macro variable somewhere in a SAS program, you can reuse that value in another part of the program that will be compiled later.
PG
Super User
Posts: 5,509

Re: Refer a variable

Posted in reply to saslovethemost

I can think of at least 10 topics that would be more important to learn about in a DATA step:

 

_n_

variable lists

arrays

DO loops

first. and last.

MERGE

multiple SET statements

RETAIN

sum statement

setting lengths of character variables

 

To address your question, refer to the variable by the variable name.  Any other way isn't important until much later in your SAS education.  Spend your time wisely!

Ask a Question
Discussion stats
  • 6 replies
  • 347 views
  • 0 likes
  • 5 in conversation