I have a list of macro variables as shown below:
%let e = 41 and so on.
I would like to convert this to a sas dataset in the manner of
a b c d e
40 55 25 38 41
I could not find anything on a quick way to do this. All I can think of is writing a data step with datalines to create the dataset. Is there a quicker way to do it, given I have large number of variables? Thank you!
Wednesday - last edited Thursday
Are all your values numeric?
Can you use all existing macro variables without omitting any?
You should be able to do something like this, but I can't test this now so I can't work out the final details until tomorrow:
select name || '=' || value into : varlist separated by ';' from dictionary.macros
where scope ne 'AUTOMATIC';
There are a few details to work out ... SCOPE is probably the wrong variable name for the WHERE clause ... in fact all the names from dictionary.macros need to be checked To patch the code, you will need to look at the structure of dictionary.macros.
The original program wasn't too far off. Here's a modified version that should work a little better:
select catx('=', name, value) into : varlist separated by ';' from dictionary.macros
where (scope ne 'AUTOMATIC') and (substr(name, 1, 3) not in ('SQL', 'SYS') );
It generates assignment statements for all your macro variables, however ...
It works properly for numeric variables only, since it generates statements like a=5; It won't add quotes around the "5" unless you get fancier with the code.
From where does this arbitrary heap of macro variables originate? You might alleviate your problems by storing the values in a dataset from the start.