hello,
I have a condition step data step based on a promot which could have more than values
Here is the orignial dataset
data toy_price;
infile datalines delimiter=',';
input toy$ cost;
AB,1
AC,10
CD,1
xx,1
AC,2
;
run;
There is promot(MONTH) which use could have select values from a list: Jan, Feb, March, April.As long as user selected Feb, like Jan, Feb, or Feb and March, or Jan, Feb and April, I want to execute a datastep, creating a new data set data TOYS. data TOYs; set TOY_PRICE: run;
I implement the code like below:
%macro TOYS_OUT;
%do i=1 %to &Month_COUNT;
%put &i;
%if "&&MONTH_COUNT&i" = 'En' %then %do;
data TOYS;
set TOY_PRICE:
run;
%end;
%end;
%mend;
%TOYS_OUT;
somehow it does not work. The TOYs dataset is not generated at all. Any ideas?
Macro is based on text . He take everything as text, you don't need quote either double or single.
%if "&&MONTH_COUNT&i" = 'En' %then %do;
---->
%if &&MONTH_COUNT&i = En %then %do;
Ksharp
warning and error:
WARNING: APPARENET SYMBOLIC REFERENCE MONTH_COUNT1 NOT RESOLVED.
ERROR: A character was found in the $EVAL function or %IF condition where a numeric operand is required. The condition was:
&&MONTH_COUNT=FEB
ERROR: The macro TOYS_OUT will stop executing.
Somehow, the refernece the prompt value is not recognized?
How is your macro variable Month_Count initialized ? And what about your macro variables Month_Count1, Month_Count2, Month_Count3...etc ?
It is a prompt, user can selected mutiple values from a static list.
Well obviously there is something wrong with the initialization of the macro variable month_count1. Have you checked the value of i ? Is it correctly put in the log by the %put statement you have ?
Just a thought but maybe there are blanks causing the macro variable not to resolve correctly with the double ampersand. Can you try something like as follow ?
%if %left(&&MONTH_COUNT&i) = En %then %do;
It generates different macro variables based on the number of choices a user makes.
My understanding is that you should have MONTH and MOUNT_COUNT. If the count is greater than one then you will also have MOUNT1, MONTH2, etc.
It does not look to me like you are using the right macro variable names, but anyway you should probably add:
%let month1 = &month ;
To you program so that MONTH1 will be sure to have a value with COUNT=1.
%let month1 = &month ;
%do i=1 %to &month_count;
%if "&&month&i" = "Jan" %then %do; .....
....
%end;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.