Outputting a List of Values to a Series of Macro Variables
There are a number of possible ways to extract values from a dataset and store them in a numbered list of macro variables. The following macro demonstrates a technique to achieve this using Proc SQL.
proc sql noprint; select count (distinct make) into :num_makes from sashelp.cars; select distinct make into :make_1 - :make_%left(&num_makes) from sashelp.cars; quit; %macro car_makes; %do i = 1%to &num_makes; %put make_&i=&&make_&i; %end; %mend; %car_makes;
Running the program will calculate the number of discrete values and then store each one in a macro variable with an incremental numbering.
Note that the macro variables are written to the global symbol table and so are available to be used in the "car_makes" macro. This simply writes the values to the SAS log but could perform any type of processing;
make_1=Acura make_2=Audi make_3=BMW make_4=Buick make_5=Cadillac make_6=Chevrolet make_7=Chrysler make_8=Dodge make_9=Ford make_10=GMC make_11=Honda ... more values are listed
You can see from the log that each discrete car make has been stored in a numbered set of macro variables. Â For more information on uses of Proc SQL or the Macro language view the SAS help or visit the SAS support site at www.support.sas.com.