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.
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.
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.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.