06-19-2017 08:10 AM
Macro language is NOT meant for data processing. Write this 100 times.
06-19-2017 08:17 AM
I apology if i did mistake.
But i need to run my programe for selective day. and i want to run my do loop for that.
but i am getting error that u r missing %to. So is there any possibility that i can use %do with out using %to.???
06-19-2017 08:31 AM
As @KurtBremser has mentioned, Macro language is only present to generate text, it does not do any processing. Therefore constructs used in Base SAS which is the programming language do not always carry through to Macro. Do list of values is one of these constructs.
I believe we have been over this several times before. Do data processing in Base SAS, that is what it is for. What is it your trying to do with this code?
06-19-2017 08:57 AM
data control; input i; cards; 3 6 7 9 ; run; %macro x(i); proc report data= Ivalue_&i; run; %mend; data _null_; set control; call execute('%x(' !! strip(put(i,best.)) !! ') '); run;
06-19-2017 08:32 AM
Post the code you want to run for a series of days, showing how the days are represented in the code as is (for a single run), and from where you will get the days for the dynamic execution (dataset?).
When writing repeatable code, follow this sequence:
- write code for one iteration
- identify variable parts
- replace with macro values
- create a means to supply these values (macro %do loop, datastep with call execute, ...) repeatedly
06-19-2017 08:46 AM
The %DO command does not have all of the functionality of the DO command.
To process a list I usually put the list into a macro variable and use %SCAN() to pull the individual items.
%macro x(list); %local i value ; %do i=1 %to %sysfunc(countw(&list)); %let value = %scan(&list,&i); statements using &value ; %end; %mend; %x(2 5 7);
06-19-2017 08:55 AM
Thanks for ur answer.
i have done same as alternate option.
%do part = 1 %to 6;
but for future prospect i want study this more. bcaz i have tried "in" with %do same also does not work. is there any document so i can study more for the same.
Thanks in advance for all of ur advice.
06-19-2017 09:23 AM - edited 06-19-2017 09:25 AM
Note there is no need to use %STR() around | as it is not a macro trigger. That is one good reason to use it as the delimiter in a list of values. Personally I much prefer to use spaces as delimiters since it is much easier to type and read, but that can be a problem if the values can contain spaces. If your values can contain other default delimiters for %SCAN() then you do need to use the third argument to %SCAN() to let it know what specific delimiter(s) to use. There is also a fourth argument to %SCAN() that can be used to add modifiers to control how it parses the string.
The IN operator is just a method for testing if a value appears in a list a values. Not sure what it would have to do with a DO loop.
Note that there are limitations on using the IN operator within macro code since it was not originally recognized as a keyword by the macro processor. There are system options and options on the %MACRO statement to control whether and how the IN operator works in macro code.
The SAS documentation is on-line at sas.com. I usually just GOOGLE until I find the right document and then look around.
06-19-2017 09:38 AM
06-19-2017 09:40 AM
If you do want to use %do loop, you could try this:
option minoperator mindelimiter='|';
%do part = 1 %to 30;
%if &part in &list %then
06-25-2017 11:51 PM
@slchen It's a good habit to declare your variables as local. You'll save yourself many headaches.
So this is a (slightly) better macro:
%macro test/minoperator mindelimiter='|'; %local list part; %let list=13|14|15|25|26|27; %do part = 1 %to 30; %if &part in &list %then %put &=part; %end; %mend; %test;