DATA Step, Macro, Functions and more

Storing a value in a variable ?

Reply
N/A
Posts: 0

Storing a value in a variable ?

Hi,
I would like to store the mean of a data set variable in a variable such that I could use the value without writing it myself each time I need it.
Is this possible ?
If yes, how can I proceed ?

Thank you in advance
Super Contributor
Posts: 474

Re: Storing a value in a variable ?

Not sure of what you need, but maybe storing the desired value into a SAS macro variable may solve your problem.

proc sql noprint;
select mean(VALUE) into :MEAN_VALUE from DATA;
quit;

the into: statement will load a value into a SAS macro variable through SQL.

See the online doc here:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543554.htm

From there, you just need to reference the SAS macro variable in your program, then at runtime this will be substituted by the actual value loaded previously.

for example:
data _null_;
put "Mean value is: &MEAN_VALUE";

/* or */

MEAN=&MEAN_VALUE;
put MEAN=;
run;

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
N/A
Posts: 0

Re: Storing a value in a variable ?

Yes it was what I wanted to do, your solution worked perfectly.
Many thanks from France !
Ask a Question
Discussion stats
  • 2 replies
  • 114 views
  • 0 likes
  • 2 in conversation