I am trying to export multiple excel files based on a user inputted macro value Job.
Job will look like this (user input)
So, if the user inputs three jobs, three files will be created:
However, when I run the code below -- I cannot seem to get the export statement to subset the data successfully and output each individual file
The error returns %SCAN has too many arguments:
%macro loop; %local i nextjob; %do i=1 %to %sysfunc(countw("&job.",",")); %let nextjob = %scan(&job., &i); proc export data = temp.IDs_SUM (where=(jobid = "&nextjob.")) outfile="/USERFOLDER/OUTPUT_&nextjob..xlsx" DBMS=XLSX REPLACE; run; %end; %mend loop; %loop;
Any tips on what I am doing wrong?
Basic issue is including commas in a list that will be used as a macro parameter.
Try making the list look like this:
129692 135534 135512
%let job = 129692 135534 135512;
also the quotes in the countw likely aren't needed
%let job = 129692 135534 135512; %macro dummy; %do i=1 %to %sysfunc(countw(&job," ")); %let nextjob = %scan(&job.,&i); %put Nextjob is &nextjob ; %end; %mend; %dummy;
Note that with the commas you were generating
%scan(129692, 135534, 135512, &I) which is pretty obviously not quite correct.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.