BookmarkSubscribeRSS Feed
YW_CA
Calcite | Level 5

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?

6 REPLIES 6
Ksharp
Super User

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

YW_CA
Calcite | Level 5

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?

Florent
Quartz | Level 8

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

YW_CA
Calcite | Level 5

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

Florent
Quartz | Level 8

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;

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 938 views
  • 0 likes
  • 4 in conversation