I'm trying to run a simple proc surveylogistic using one variable at a time to retrieve trends overtime for each variable. I don't want to have to copy/paste the variables each time and re-run (there are 55 of them, total). So I thought about creating an ARRAY containing the list of variables, and telling SAS to iterate through that list, one at a time, then finally print each of those "final outputs" into the results window.
But I'm not sure how to do this. Or if there is a better option, considering I have to create the ARRAY in the data step, then somehow pass it to the proc step? Below is an example of what I've been attempting, based off a suggestion I saw elsewhere on another forum:
*Create array list;
ARRAY roll [4]
var1 var2 var3 var4;
DO i=1 to 4;
*Select only table of interest;
ODS Select ParameterEstimates;
ODS output ParameterEstimates= roll[i];
PROC SURVEYLOGISTIC Data=rollrpt3 Total=TOTALS_DATASET NOMCAR;
Weight wghtvar;
Strata strat_var;
Model roll[4] = year;
Run;
ODS close;
*Print estimate and its associated P-value for trend;
Proc print data=roll[i];
Var Variable ProbT;
Where Variable="year";
run;
Quit;
You could use a macro, such as this example:
%let varnames=var1 var2 var3 var4;
%macro dothis;
%do i=1 %to %sysfunc(countw(&varnames));
%let thisname=%scan(&varnames,&i,%str( ));
proc surveylogistic data=rollrpt3 /* whatever other options you want */ ;
model &thisname = year;
/* Any other needed statements in PROC SURVEYLOGISTIC */
run;
%end;
%mend;
%dothis
I am skeptical that SURVEYLOGISTIC is a good tool to model a variable named YEAR as a predictor variable. But I don't know the goals of this study ... why don't you tell us the goals?
To tell you the truth, I was thinking year should be a CLASS variable if you are doing a study with random sampling over many years. But I don't know your data. And I don't know your study design.
Also, there's no way I can tell what PROC you should be using since I don't know what VAR1 is. For PROC SURVEYLOGISTIC, you need to have VAR1 as categories. If VAR1 is continuous, then you would want to use PROC SURVEYREG.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.