DATA Step, Macro, Functions and more

condition steps based promot with multiple values

Reply
Occasional Contributor
Posts: 16

condition steps based promot with multiple values

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?

Super User
Posts: 9,682

Re: condition steps based promot with multiple values

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

Occasional Contributor
Posts: 16

Re: condition steps based promot with multiple values

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?

Frequent Contributor
Posts: 127

Re: condition steps based promot with multiple values

How is your macro variable Month_Count initialized ? And what about your macro variables Month_Count1, Month_Count2, Month_Count3...etc ?

Occasional Contributor
Posts: 16

Re: condition steps based promot with multiple values

It is a prompt, user can selected mutiple values from a static list.

Frequent Contributor
Posts: 127

Re: condition steps based promot with multiple values

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;

Super User
Super User
Posts: 6,502

Re: condition steps based promot with multiple values

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;

Ask a Question
Discussion stats
  • 6 replies
  • 284 views
  • 0 likes
  • 4 in conversation