- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Run the below code to learn about an alternative:
data _NULL_;
set sashelp.class;
call symputx('NAME'!!strip(put(_N_,8.)),name);
run;
%PUT &=NAME1;
%PUT &=NAME2;
%PUT &=NAME3;
%PUT &=NAME19;
Cheers,
Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%LET creates macro variables.
There are many other ways to create macro variables from tables - CALL SYMPUTX() or PROC SQL are two ways.
So let's look at creating macro variables for all the names in the CLASS data set, with a data step and a macro.
proc sql noprint;
select name into :sql_name1-
from sashelp.class;
quit;
%put &sql_name1.;
%put &sql_name19.;
And via data step:
data _null_;
*for debugging;
*data demo;
set sashelp.class;
macro_variable_name = catt('dataStep_name', put(_n_, 2. -l));
call symputx(macro_variable_name, name);
run;
%put &dataStep_name1;
%put &dataStep_name19.;
@vicmaria98 wrote:
I currently have code with a bunch of %let statements which are then used to do calculations with my data. My goal is to create a macro that reads in a sas table and changes those %let value statements. Is there a way to assign %let to variable values in a table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I currently have code with a bunch of %let statements which are then used to do calculations with my data.
It's much easier to do calculations in a DATA step than in macro variables.
My goal is to create a macro that reads in a sas table and changes those %let value statements. Is there a way to assign %let to variable values in a table?
So your data is in a SAS "table", do the calculations in a DATA step. Much much easier. Macros are likely unnecessary.
Why do you think macro variables will help here?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Moving data into macro-variables for calculations is a bad idea in approximately 100% times. So please tell us what you are trying to. I am sure, that a solution can be developed that allows the data to stay in its natural living space.