11-27-2014 04:31 AM
Hope this problem seems interesting.
- Macro Variables
- That I want to put in a new table (can do it easily in an existing table but i wanted to see if i can push my luck)
- Run a loop
input rmse $10.;/*adding it as character as it didn't work with numeric and thought i can easily convert later on*/
rmse=deqoute(resolve(quote(rmse)));/*to ensure that macro variable gets read*/
do i=1 to 3;
Problem: I get the last rmse populated thrice in the table instead of the individual rmse. Until now unable to find a resource that uses macro variable in a datelines with a loop.
Any help is much appreciated as this will go towards building a table with lots of other stats in.
11-27-2014 04:53 AM
Sorry, have to ask why? You must have put the data into the macro variables somewhere and now your putting them back into a datastep, seems like going round in circles to me. There are many ways to get macro variables: symget is one, you could also just use the SAS metadata tables:
set sashelp.vmacro (where=(name in ("XYZ","ERT"...) keep=value);
This returns a dataset with a list of values held in the macro variables in the in list.
I return however to my original question - why? Provide some background on the problem as 99% of the time there is no need for macro anything, just a way of thinking about the data and your process.
11-28-2014 10:24 AM
You are right. Maybe there is no need for a macro.
The issue is: I have ods output and other tables where stats are stored. I need the stats (some from each of the tables) in a particular pre-formatted table design. Hence I thought of putting macro variables into a new table.
11-29-2014 11:41 AM
Yes, something I do all the time. My approach, without using any macro code:
create table OUTPUT
COL1 char(200) label "Stat",
COL2 char(200) label "Result"
insert into OUTPUT
COL2=(select put(n,3.) from MEANS_OUTPUT)
COL2=(select put(mean,5.2) from MEANS_OUTPUT)
Think it seems a bit long winded, fine combine the approach with arrays or datasets of parameters, and call execute and you can generate a whole output table with a datastep of 5 or 6 rows, formatted etc.
11-27-2014 05:13 AM
As often, you confuse macro execution with data step execution; i is a data step variable, &i is a macro variable, both are completely disconnected.
If you think you need the macro, do it this way:
%do i = 1 %to 3;
Need further help from the community? Please ask a new question.