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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.