Hi all,
I'm a very newbie at SAS programming, so please bear with me.
I was writing a piece of code which includes a %LET statement. I would like to assign more than one value to a %let statement similar to below:
%let item=('A120XXX', 'A250XXX', 'A150XXX')
My item are way more than 3 and I would like to use a wildcard like
%let item=('A***XXX') ;
SAS do not return any results.
Is there a way to get around this?
Thanks
... and yes, %do loops are easier
%macro fluff2(prefix=,infix=,suffix=);
%local I J K value;
%let value =;
%do I = 1 %to %sysfunc(countw(&prefix,%str( )));
%do J = 1 %to %sysfunc(countw(&infix ,%str( )));
%do K = 1 %to %sysfunc(countw(&suffix,%str( )));
%let value = &Value. %scan(&Prefix ,&I
)%scan(&Infix ,&J
)%scan(&Suffix,&K);
%end;
%end;
%end;
&value
%mend;
%Let Item2 = %fluff2(prefix=A,infix=&ItemNmbrs,suffix=XXX);
%put Item2:&Item2;
Perhaps you need to describe in more detail how you suppose to use this macro variable "item"? Also, what does your items represent?
Macro variable values are generally seen as plain text by the compiler, so if you wish to apply some logic in the assignment, you have to solve differently.
If your wild-card should represent numerical values in a range, you can perhaps use %do-loops to generate the values (but that needs to be done within a macro definition, not in open code).
The data step offers more flexibility in this area, so perhaps you can create your macro variable within a data step using call symput instead?
in order to fill in the range of values which asterisks represent
you have to provide that list:
%Let ItemNmbrs = 120 150 250;
%macro fluff(prefix=,infix=,suffix=);
%local I J K dim_I dim_J dim_K value;
%let I = 1;
%let J = 1;
%let K = 1;
%let dim_I = %sysfunc(countw(&prefix,%str( )));
%let dim_J = %sysfunc(countw(&infix ,%str( )));
%let dim_K = %sysfunc(countw(&suffix,%str( )));
%let value =;
%Loop:
%let Pfx = %scan(&Prefix,&I);
%let Nfx = %scan(&Infix ,&J);
%let Sfx = %scan(&Suffix,&K);
%let value = &Value. &Pfx.&Nfx.&Sfx.;
%if &I eq &Dim_I
and &J eq &Dim_J
and &K eq &Dim_K %then %do;
&value
%*goto %exit;
%return;
%end;
%if &I lt &Dim_I %then %let I = %eval(&I+1);
%if &J lt &Dim_J %then %let J = %eval(&J+1);
%if &K lt &Dim_K %then %let K = %eval(&K+1);
%goto Loop;
%exit:
%mend;
%Let Item = %fluff(prefix=A,infix=&ItemNmbrs,suffix=XXX);
%put Item:&Item;
Ron Fehd loop maven
http://www.sascommunity.org/wiki/Do_which_loop_until_or_while
... and yes, %do loops are easier
%macro fluff2(prefix=,infix=,suffix=);
%local I J K value;
%let value =;
%do I = 1 %to %sysfunc(countw(&prefix,%str( )));
%do J = 1 %to %sysfunc(countw(&infix ,%str( )));
%do K = 1 %to %sysfunc(countw(&suffix,%str( )));
%let value = &Value. %scan(&Prefix ,&I
)%scan(&Infix ,&J
)%scan(&Suffix,&K);
%end;
%end;
%end;
&value
%mend;
%Let Item2 = %fluff2(prefix=A,infix=&ItemNmbrs,suffix=XXX);
%put Item2:&Item2;
Where to you look to find the part that is represented by ***.
1) variable names.
2) data values
3) somewhere else
?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.