%let var1=12MAY2017;
proc sql ;
select H_date into:var2 seperated by ',' from Holiday_list ;
quit;
var2 will contain values from 01JAN2017 to 31DEC2017 (holiday list for 2017)
how to see if var1 contains values in var2 ??
Shubham,
So far you got a lot of good hints, but not a complete solution.
It is quite simple, though:
%sysfunc(indexw(&var2,&var1)) will give you a positive number if &VAR1 is present as a word in &VAR2, otherwise you will get 0.
So you can use it in a macro like
%if %sysfunc(indexw(&var2,&var1)) %then...
Regards,
Søren
Use %do%while loop witth %scan function.
It's very easy.
I want to use this as
if &va1 contains value in &var2 then do;
-----------------------
end;
else do;
------------------------------------
end;
can u tell me how can i compare in an if condition ?
Try next code:
data want;
set have;
retain holydays "&var2"; /* the list */
if index(holydays,"&var1") then do;
---- holyday action ----
end;
else do;
------
end;
run;
I have edited the code to repair some typos.
thank you sir, it worked !
Using SYSFUNC will allow you to use the standard SAS FINDW or INDEXW functions.
Flag will be 0 if not in list, integer otherwise:
%Let Flag=%Index("&var2",&var1.);
.. and you have a typo in "separated".
Why use a macro variable list at all?
%let var1=12MAY2017;
%let flag = 0;
data _null_;
set Holiday_list;
if var2 = "&var1"d then call symput('flag','1');
run;
Assuming that var2 in Holiday_list is a SAS date variable (numeric with date format assigned)
Shubham,
So far you got a lot of good hints, but not a complete solution.
It is quite simple, though:
%sysfunc(indexw(&var2,&var1)) will give you a positive number if &VAR1 is present as a word in &VAR2, otherwise you will get 0.
So you can use it in a macro like
%if %sysfunc(indexw(&var2,&var1)) %then...
Regards,
Søren
You can use the %inm macro to replicate the functionality of the SAS command IN as a macro
The macro is explained here, it's pretty simple
https://groups.google.com/forum/#!topic/comp.soft-sys.sas/fWcSDgg11tE
You want put it in Data Step or A Macro ? %let var1=12MAY2017; data holiday_list; do h_date='01jan2017'd to '01jun2017'd ; output; end; run; proc sql noprint; select put(H_date,date9.) into:var2 separated by ',' from Holiday_list ; quit; data x; set holiday_list; if findw(symget('var2'),"&var1") then put 'found'; else put 'not found'; run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.