Using a proc freq output as a selection criteria for an export macro

Reply
New Contributor
Posts: 2

Using a proc freq output as a selection criteria for an export macro

I need to take a variable created by the output of a proc freq and use it to iterate and select several proc export files. The point is to automate a selection and output criteria. 

 

Using the following generates 28 unique rows.

 

  proc freq data=MatchedLeads;
    tables campaigngroup_name / out=OutFreq(rename=(campaigngroup_name=Selector)keep=campaigngroup_name) ;
  run;

 

Now I want to take the 28 observation, one variable (Selector) and use it to create an iterative process that will create 28 separate export files.

 

Currently my proc export code looks like this.

 

   proc export data= MatchedLeads outfile="\\sysdir\exportdatamatched.xlsx"
     dbms=xlsx replace;
   run;

 

This just gives me one huge data set. I need it to select and export based on the results from the freq above.

Respected Advisor
Posts: 3,066

Re: Using a proc freq output as a selection criteria for an export macro

I need it to select and export based on the results from the freq above.

 

I don't understand this, how you export based on the 28 rows from PROC FREQ. Please explain in detail.

--
Paige Miller
Super User
Super User
Posts: 9,599

Re: Using a proc freq output as a selection criteria for an export macro

I am going to presume call execute:

proc freq data=MatchedLeads;
  tables campaigngroup_name / out=OutFreq (rename=(campaigngroup_name=Selector) keep=campaigngroup_name) ;
run;

data _null_;
  set outfreq;
  call execute('proc export data= MatchedLeads outfile="\\sysdir\exportdatamatched.xlsx"
                  dbms=xlsx replace;
                run;');
run;

 

This will create one export statement for each row in the freq output, you will need to add your filters.

Super User
Posts: 6,785

Re: Using a proc freq output as a selection criteria for an export macro

I think this is headed in the right direction with CALL EXECUTE.  I imagine the final destination is more like this:

 

 

proc freq data=MatchedLeads;
  tables campaigngroup_name / out=OutFreq (rename=(campaigngroup_name=Selector) keep=campaigngroup_name) ;
run;

data _null_;
  set outfreq;
  call execute('data subset; set MatchedLeads;');
  call execute('where campaigngroup="' || selector || '"; run;');
  call execute('proc export data=subset outfile=');
  call execute('"\\sysdir\' || trim(selector) || '.xlsx" dbms=xlsx replace; run;');
run;

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 54 views
  • 2 likes
  • 4 in conversation