Hello new to SAS, and I am running a macro that loops through the different classes in a variable, in this case, urban, rural, and national.
I want to subset each of this data into a temporary table for each pass through to run a paired T-test on each class, however I am having issues with sub setting the data.
(This is just a snapshot of the data, there are also other variables that I want to group by excluded)
Obs Geography Var1 Var2123
Urban | -0.01438 | -0.12000 |
Rural | -0.08528 | -0.02000 |
National | -0.03121 | -0.10000 |
The code in the macro that does this
The new dataset that is created is ClassType, which just includes either just all of the "Urban" "Rural" or "National" data
group_var = Geography (In this case) and ClassVar stores the observations of Geography
%MACRO ttest_by_class(ds, group_var, class_vars, numeric_var1, numeric_var2, output);
%LET num_class_vars = %SYSFUNC(COUNTW(&class_vars.));
%DO i = 1 %TO &num_class_vars.;
%LET ClassVar = %SCAN(&class_vars, &i, ' ');
DATA ClassType;
SET &ds.;
IF(&group_var. = &ClassVar.);
RUN;
...
However, when I run the Data step, the tables that it produces contains are empty, but when I change &ClassVar. to the individual strings "Urban" , it works fine. Is this just not possible with macro variables, or is there a way to convert to string?
Also if there an easier way to do what I am planning on doing, I would like to know.