BookmarkSubscribeRSS Feed
SAS93
Quartz | Level 8

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;

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
SAS93
Quartz | Level 8
Thank you for the suggestion! I'm using survey data to assess change in overall prevalence of various dichotomous indicators (the variables in my list) over a continuous variable for time (years) instead of setting it as categorical. The prevalence estimates need to be properly weighted, so survey procedures it is.
Would you recommend using surveyREG instead of logistic?
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 375 views
  • 0 likes
  • 2 in conversation