BookmarkSubscribeRSS Feed
CarterM
Calcite | Level 5

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.

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Astounding
PROC Star

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;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 442 views
  • 2 likes
  • 4 in conversation