Help using Base SAS procedures

Proc Freq in a macro loop

Reply
Contributor
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,174

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 http://support.sas.com/ website.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

repetitive code dictionary columns site:sas.com
SAS Super FREQ
Posts: 8,743

Re: Proc Freq in a macro loop

Hi:
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.

cynthia
[pre]

proc freq data=work.mydata(keep=fromdate: thrudateSmiley Happy;
tables _character_;
run;
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 317 views
  • 0 likes
  • 3 in conversation