BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shubham13
Calcite | Level 5

%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 ??

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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

View solution in original post

10 REPLIES 10
Saurabh13
Fluorite | Level 6

Use %do%while loop witth %scan function. 

It's very easy.

 

shubham13
Calcite | Level 5

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 ?

 

Shmuel
Garnet | Level 18

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.

shubham13
Calcite | Level 5

thank you sir, it worked !

 

Reeza
Super User

Using SYSFUNC will allow you to use the standard SAS FINDW or INDEXW functions. 

user24feb
Barite | Level 11

Flag will be 0 if not in list, integer otherwise:

 

%Let Flag=%Index("&var2",&var1.);

.. and you have a typo in "separated".

 

Kurt_Bremser
Super User

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)

s_lassen
Meteorite | Level 14

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

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Ksharp
Super User
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;


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
  • 10 replies
  • 3914 views
  • 0 likes
  • 9 in conversation