Help using Base SAS procedures

Proc Freq in a macro loop

Posts: 74

Proc Freq in a macro loop

Hi All,

I have a file which has date fields(data is in text format eg:'20090112')
for eg fromdate1,fromdate2,fromdate3, thrudate1 thrudate2 thrudate3.
I wanted to run a proc freq on these date fileds,is it possible to include the proc freq in a do loop with in a macro?

Thanks in advance.
Super Contributor
Super Contributor
Posts: 3,176

Re: Proc Freq in a macro loop

Sure, you use DICTIONARY.COLUMNS with PROC SQL to generate a list of the macro variables you want to process, and within a SAS macro, you iterate through the macro variable list through substituting each variable on the TABLES statement.

There are references in the archives as well as topic-related reference papers / material available at the SAS support website.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

repetitive code dictionary columns
Posts: 9,370

Re: Proc Freq in a macro loop

Another possibility. Let's say you have a dataset called WORK.MYDATA, then you could do this...without needing a macro program. Because you are using the colon modifier to keep any variable that starts "fromdate" or "thrudate" (assuming they are character variables), then using the _character_ special variable reference will ONLY have proc freq create one table for each variable -- fromdate1 through fromdaten, and thrudate1 through thrudaten, etc.


proc freq data=work.mydata(keep=fromdate: thrudateSmiley Happy;
tables _character_;
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation