arrayssasassociationsfrequencydo-loops

Use Array in SAS proc freq?


I am doing an exploratory analysis to see if any variables are associated with someone "switching" from one type of treatment to another. I am running fisher's exact tests (because of a small sample size) to test associations before coming back to my team with any recommendations on how to proceed with the analysis.

The issue I am running into is that there are 22 variables that need to be compared to the "switch" variable and while I could hardcode every combination, it would be concise and cleaner if I could use an array or do loop to code these 22 tests in just a few lines.

I was able to successfully create an array with the variables I need.

Any advice would be greatly appreciated!! I had tried to code the following

proc freq data=dataset;
tables switch_var*comp_vars(22)/fisher;
run;

When I did it returned with the following error : ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 200-322: The symbol is not recognized and will be ignored.


Solution

  • Arrays are only valid in data steps and some procedures (but not PROC FREQ).

    Shortcut lists are more appropriate here most likely, if you have a naming convention or if the variables are side by side.

    Examples:

    proc freq data=dataset;
    tables switch_var*(comp_vars1-comp_vars22)/fisher;
    tables switch_var*(comp_vars:)/fisher;
    tables switch_var*(measurement1--end_variable22)/fisher;
    run;
    

    Various ways to list variables are listed in this blog post: https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html