BookmarkSubscribeRSS Feed
Pyrite | Level 9

Hi everyone, i have a data set similar to below with 60 columns(both numeric and character). I'm planning to take then in to loop one by one and perform descriptive analysis. before they enter into the loop they must undergo a checking for their datatype. This is an interesting task which i'm planning to perform by the help of using arrays(as I've heard of the power of using arrays and used before).


After going through several white papers i have came up with a sample untested code and it would be great to have your help to take my array learning to a next level.  


Kindly do comment.


data temp;
01001 56 F 22.3 34.5 Y

01001 60 M 29.3 41.5 N

01001 35 F 26.3 22.5 Y;

01001 23 M 19.3 34.5 Y;

01001 34 F 18.3 41.5 Y;



%macro descriptive(first=, last= );

data _null_;

set temp;

array variables AGE--INFECTION;

%do over variables;

%if datatyp(variables[i] eq CHARACTER) %then %do;

proc freq data=temp;

var variables[i];



%else %if datatyp(variables[i] eq NUMERIC) %then %do;

proc means data =temp;

var variables[i];



%mend descriptive;


Super User
Arrays can only hold one type of variable so this won't work for you. Instead for what you're trying to do, I suggest looking at the VINFO() and maybe VNEXT() or instead consider getting the types from proc contents ahead of time or sashelp.vcolumn (dictionary.column) table.

You could also use _character_ to refer to all character variables or _numeric_ to refer to all numeric.
Or AGE-numeric-INFECTION to reference only numeric variables between the variables.

Note that you cannot nest your code in that manner either, you cannot nest PROC FREQ within a data step or PROC MEANS. So your entire code structure is problematic.

If you want to summarize all variables from a data set instead use the following code:

proc freq data=temp;
table AGE-character-Infection;

proc means data=temp;
var AGE-numeric-Infection;

That will run all at once. I'll leave you to determine how you want to turn that into a macro.

Note you have first/last in your macro definition but never use them.
Super User

Some references for you:


Here's a tutorial on using Arrays in SAS


UCLA introductory tutorial on macro variables and macros

Tutorial on converting a working program to a macro

This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂

Examples of common macro usage



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2 in conversation