03-01-2016 03:34 AM
I have a dataset with about 50 variables with one value in each variable.
Is there any easy way to create 50 macro-variables of these variables, like:
Many thanks in advance!
03-01-2016 03:57 AM
For starters, having 50+ variables is not very convenient, which you now experiencing...
Use an array in the data step, and do call symput.
But again, it's quite inconvenient to handle 50+ macro variables.
Whats the use case?
03-01-2016 04:33 AM
Why would you want to do this? Macro language is not for processing data, that is what Base SAS is for. Trying to do things this way will lead to messsy hard to read, and hard to maintain code which does nothing a simple datastep would not do. Post some example test data (as a datastep), and what you would like to achieve and we can show you some code.
03-01-2016 04:41 AM - edited 03-01-2016 04:43 AM
Here is an example :
proc transpose data=sashelp.class(obs=1) out=temp; var _all_; run; data _null_; set temp; call symputx(_name_,col1); run; %put _user_;
03-01-2016 06:56 AM
I agree that many macro-var is not convinient. However my situation is the following:
I have a macro which I want to run for about 50 variables. The macro calculates standardized differences for one variable each run.
and so on...
Of course I can write all 50 variables here BUT my issue is that every time I update my model with new data, some variables might not have enough data to run the macro(calculate the standardized difference). For example, it might be that the variable CHF can not be calculetd in som runs. In these situation the macro will terminate.
So I am thinking of programming some dynamic thing here which tell the macro which variables to be run.(I now in each update which variables possible to run).
Thanks for any advice!
03-01-2016 08:24 AM
You have a whole load of options here. Firstly, consider putting another variable in your data, and using that as a by group, it will be the easiest to code and maintain and run quickest. E.g.:
data have is:
BYVAR your variables
proc means data=have; by byvar; ... run;
This would always be my number one option, and should cover most events.
You could also do this:
data _null_; do i="var1","var2","var3"; call execute('proc means data=have; var='||strip(i)||'; run;'); end; run;
You could also transpose your data, and use arrays. With some proper test data in the form of a datastep i can provide code.
03-01-2016 08:30 AM
You can iterate using a single macro variable. Here's a reference with some details: