<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create multiple IF statements for each argument in VaRList macro varaibble in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616878#M180686</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;User define vector of dates.&lt;/P&gt;
&lt;P&gt;For each of the argument I need to produce&amp;nbsp; IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let vector1='20NOV2019'd+'25NOV2019'd+'02DEC2019'd+'05DEC2019'd+'10DEC2019'd+'15DEC2019'd;
%let vector2=20NOV2019+25NOV2019+02DEC2019+05DEC2019+10DEC2019+15DEC2019;
%let n=6;
%put &amp;amp;vector1;
%put &amp;amp;vector2;
%put &amp;amp;n;


/*I need to produce following statements */
/*Then I will use it */
/*IF OFFER_DATE='20NOV2019'd then Accum_Loan=AccumTill_20NOV2019;*/
/*IF OFFER_DATE='25NOV2019'd then Accum_Loan=AccumTill_25NOV2019;*/
/*IF OFFER_DATE='02DEC2019'd then Accum_Loan=AccumTill_02DEC2019;*/
/*IF OFFER_DATE='05DEC2019'd then Accum_Loan=AccumTill_05DEC2019;*/
/*IF OFFER_DATE='10DEC2019'd then Accum_Loan=AccumTill_10DEC2019;*/
/*IF OFFER_DATE='15DEC2019'd then Accum_Loan=AccumTill_15DEC2019;*/


%macro mmacro; 
%do j=1 %to &amp;amp;n.;
%let date=%scan(&amp;amp;vector1.,&amp;amp;j.,+);
%let dateName=%scan(&amp;amp;vector2.,&amp;amp;j.,+);
IF OFFER_DATE=&amp;amp;date. then Accum_Loan=AccumTill_&amp;amp;date.;
%end;
%mend;
%put %mmacro;
/***I don't get the list of the statements as I want*/

Data b;
set a;
%mmacro;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Jan 2020 11:50:26 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-01-13T11:50:26Z</dc:date>
    <item>
      <title>Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616878#M180686</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;User define vector of dates.&lt;/P&gt;
&lt;P&gt;For each of the argument I need to produce&amp;nbsp; IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let vector1='20NOV2019'd+'25NOV2019'd+'02DEC2019'd+'05DEC2019'd+'10DEC2019'd+'15DEC2019'd;
%let vector2=20NOV2019+25NOV2019+02DEC2019+05DEC2019+10DEC2019+15DEC2019;
%let n=6;
%put &amp;amp;vector1;
%put &amp;amp;vector2;
%put &amp;amp;n;


/*I need to produce following statements */
/*Then I will use it */
/*IF OFFER_DATE='20NOV2019'd then Accum_Loan=AccumTill_20NOV2019;*/
/*IF OFFER_DATE='25NOV2019'd then Accum_Loan=AccumTill_25NOV2019;*/
/*IF OFFER_DATE='02DEC2019'd then Accum_Loan=AccumTill_02DEC2019;*/
/*IF OFFER_DATE='05DEC2019'd then Accum_Loan=AccumTill_05DEC2019;*/
/*IF OFFER_DATE='10DEC2019'd then Accum_Loan=AccumTill_10DEC2019;*/
/*IF OFFER_DATE='15DEC2019'd then Accum_Loan=AccumTill_15DEC2019;*/


%macro mmacro; 
%do j=1 %to &amp;amp;n.;
%let date=%scan(&amp;amp;vector1.,&amp;amp;j.,+);
%let dateName=%scan(&amp;amp;vector2.,&amp;amp;j.,+);
IF OFFER_DATE=&amp;amp;date. then Accum_Loan=AccumTill_&amp;amp;date.;
%end;
%mend;
%put %mmacro;
/***I don't get the list of the statements as I want*/

Data b;
set a;
%mmacro;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2020 11:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616878#M180686</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-13T11:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616881#M180687</link>
      <description>&lt;P&gt;Thanks for supplying code and what you expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like you should have used &lt;FONT face="courier new,courier"&gt;dateName&lt;/FONT&gt; at the end of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF OFFER_DATE=&amp;amp;date. then Accum_Loan=AccumTill_&amp;amp;date.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So that it becomes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF OFFER_DATE=&amp;amp;date. then Accum_Loan=AccumTill_&amp;amp;dateName.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If this is not your issue then please show your log of the code being executed including any error messages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 12:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616881#M180687</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-01-13T12:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616882#M180688</link>
      <description>&lt;P&gt;See my answer to your previous question.&lt;/P&gt;
&lt;P&gt;Dataset. Data Step. Call Execute.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 12:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616882#M180688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-13T12:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616893#M180691</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you can try this, to avoid putting formatted dates into macro variables (this could play trick on you)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* UNTESTED CODE */&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dates;
	input date:date9.;
	datalines;
20NOV2019
25NOV2019
02DEC2019
05DEC2019
10DEC2019
15DEC2019
;
run;

data _null_;
	set dates;
	call symputx("date"||left(_n_),date);
	call symputx("datef"||left(_n_),put(date,date9.));
	call symputx("nobs",_n_);
run;

data b;
	set a;
	do i=1 to &amp;amp;nobs;
		if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i then Accum_Loan=AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2020 12:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/616893#M180691</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-13T12:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617137#M180784</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;Unfortunately the last step is not working and I get an error.&lt;/P&gt;
&lt;P&gt;Please find the code that I run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
informat OFFER_DATE date9.;
format OFFER_DATE date9.;
input ID OFFER_DATE offer_Amount
AccumTil_20NOV2019  AccumTil_25NOV2019  AccumTil_02DEC2019
AccumTil_05DEC2019 AccumTil_10DEC2019   AccumTil_15DEC2019;
cards;
1 '20NOV2019'd 10 0 0 0 0 5 7
2 '20NOV2019'd 20 2 3 4 5 6 7
3 '10DEC2019'd 30 0 0 0 3 3 3 
4 '15DEC2019'd 40 0 0 0 0 0 0
5 '10DEC2019'd 50 0 0 0 0 0 0
6 '15DEC2019'd 60 0 0 0 0 0 0
7 '15DEC2019'd 70 0 0 0 0 0 0
8 '15DEC2019'd 80 0 0 0 0 0 0
9 '10DEC2019'd 90 0 7 8 9 9 9
10 '10DEC2019'd 100 0 0 0 0 0 0
;
run;

data dates;
	input date:date9.;
	datalines;
20NOV2019
25NOV2019
02DEC2019
05DEC2019
10DEC2019
15DEC2019
;
run;


data _null_;
	set dates;
	call symputx("date"||left(_n_),date);
	call symputx("datef"||left(_n_),put(date,date9.));
	call symputx("nobs",_n_);
run;
%put &amp;amp;date1;
%put &amp;amp;date2;
%put &amp;amp;date3;
%put &amp;amp;date4;
%put &amp;amp;date5;
%put &amp;amp;date6;

%put &amp;amp;datef1;
%put &amp;amp;datef2;
%put &amp;amp;datef3;
%put &amp;amp;datef4;
%put &amp;amp;datef5;
%put &amp;amp;datef6;

%put &amp;amp;nobs;


/*IT is not working!! error*/
/*ERROR 180-322: Statement is not valid or it is used out of proper order.*/
%macro mmacro; 
%do i=1 %to &amp;amp;nobs.;
if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i.. then Accum_Loan=AccumTil_&amp;amp;&amp;amp;datef&amp;amp;i..;
%end;
%mend;
%put %mmacro;


data b;
set a;
%mmacro;
run;


/*It is also not working*/
data b;
set a;
do i=1 to &amp;amp;nobs;
if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i then Accum_Loan=AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i;
end;
Run;


/*By writing the IF statements manually it is  working well*/
data b;
set a;
IF OFFER_DATE='20NOV2019'd then Accum_SUM_HALV=AccumTil_20NOV2019;
IF OFFER_DATE='25NOV2019'd then Accum_SUM_HALV=AccumTil_25NOV2019;
IF OFFER_DATE='02DEC2019'd then Accum_SUM_HALV=AccumTil_02DEC2019;
IF OFFER_DATE='05DEC2019'd then Accum_SUM_HALV=AccumTil_05DEC2019;
IF OFFER_DATE='10DEC2019'd then Accum_SUM_HALV=AccumTil_10DEC2019;
IF OFFER_DATE='15DEC2019'd then Accum_SUM_HALV=AccumTil_15DEC2019;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 06:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617137#M180784</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-14T06:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617140#M180785</link>
      <description>&lt;P&gt;The ERRORs are caused by this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %mmacro;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as you call the macro outside of a data step, and it creates data step code. Remove this unnecessary statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get a macro to work, &lt;STRONG&gt;ALWAYS START WITH VALID, WORKING, NON-MACRO SAS CODE!!!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a data step that works for a few of your dates, THEN make it dynamic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if offer_date = 21873 then accum_loan = accum_til_20NOV2019;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will only work if accum_til_20NOV2019 is already present in the dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 06:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617140#M180785</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-14T06:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617141#M180786</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;Is there a way to fix the code that way3 and way4 will work also?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
informat OFFER_DATE date9.;
format OFFER_DATE date9.;
input ID OFFER_DATE offer_Amount
AccumTill_20NOV2019  AccumTill_25NOV2019  AccumTill_02DEC2019
AccumTill_05DEC2019 AccumTill_10DEC2019   AccumTill_15DEC2019;
cards;
1 '20NOV2019'd 10 0 0 0 0 5 7
2 '20NOV2019'd 20 2 3 4 5 6 7
3 '10DEC2019'd 30 0 0 0 3 3 3 
4 '15DEC2019'd 40 0 0 0 0 0 0
5 '10DEC2019'd 50 0 0 0 0 0 0
6 '15DEC2019'd 60 0 0 0 0 0 0
7 '15DEC2019'd 70 0 0 0 0 0 0
8 '15DEC2019'd 80 0 0 0 0 0 0
9 '10DEC2019'd 90 0 7 8 9 9 9
10 '10DEC2019'd 100 0 0 0 0 0 0
;
run;

data dates;
	input date:date9.;
	datalines;
20NOV2019
25NOV2019
02DEC2019
05DEC2019
10DEC2019
15DEC2019
;
run;


data _null_;
	set dates;
	call symputx("date"||left(_n_),date);
	call symputx("datef"||left(_n_),put(date,date9.));
	call symputx("nobs",_n_);
run;
%put &amp;amp;date1;
%put &amp;amp;date2;
%put &amp;amp;date3;
%put &amp;amp;date4;
%put &amp;amp;date5;
%put &amp;amp;date6;

%put &amp;amp;datef1;
%put &amp;amp;datef2;
%put &amp;amp;datef3;
%put &amp;amp;datef4;
%put &amp;amp;datef5;
%put &amp;amp;datef6;

%put &amp;amp;nobs;

/*Way1-Maunal writing IF statements*/
/*By writing the IF statements manually it is  working well*/
data b;
set a;
IF OFFER_DATE='20NOV2019'd then Accum_SUM_HALV=AccumTill_20NOV2019;
IF OFFER_DATE='25NOV2019'd then Accum_SUM_HALV=AccumTill_25NOV2019;
IF OFFER_DATE='02DEC2019'd then Accum_SUM_HALV=AccumTill_02DEC2019;
IF OFFER_DATE='05DEC2019'd then Accum_SUM_HALV=AccumTill_05DEC2019;
IF OFFER_DATE='10DEC2019'd then Accum_SUM_HALV=AccumTill_10DEC2019;
IF OFFER_DATE='15DEC2019'd then Accum_SUM_HALV=AccumTill_15DEC2019;
Run;

/*Way2*/
/*It is working well*/
%macro want();
	%do i=1 %to &amp;amp;nobs;
	Data wanted_&amp;amp;i(Keep=ID AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i);
	set a;
	if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i then Accum_Loan=AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i;
    Run;
	%end;
%mend;
%want

data b;
merge a wanted_: ;
by ID;
Run;

/*Way3*/
/*IT is not working!! error*/
/*ERROR 180-322: Statement is not valid or it is used out of proper order.*/
%macro mmacro; 
%do i=1 %to &amp;amp;nobs.;
if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i.. then Accum_Loan=AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i..;
%end;
%mend;
%put %mmacro;


data b;
set a;
%mmacro;
run;


/*Way4*/
/*It is also not working*/
data b;
set a;
do i=1 to &amp;amp;nobs;
if OFFER_DATE=&amp;amp;&amp;amp;date&amp;amp;i then Accum_Loan=AccumTill_&amp;amp;&amp;amp;datef&amp;amp;i;
end;
Run;




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 07:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617141#M180786</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-14T07:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create multiple IF statements for each argument in VaRList macro varaibble</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617144#M180787</link>
      <description>&lt;P&gt;You still have that wrong %put in there, causing the ERRORs in way 3.&lt;/P&gt;
&lt;P&gt;Way 4 can't work, you can't mix data step and macro code like this; we've covered that a gazillion times by now.&lt;/P&gt;
&lt;P&gt;THIS WORKS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
informat OFFER_DATE date9.;
format OFFER_DATE date9.;
input ID OFFER_DATE offer_Amount
AccumTill_20NOV2019  AccumTill_25NOV2019  AccumTill_02DEC2019
AccumTill_05DEC2019 AccumTill_10DEC2019   AccumTill_15DEC2019;
cards;
1 '20NOV2019'd 10 0 0 0 0 5 7
2 '20NOV2019'd 20 2 3 4 5 6 7
3 '10DEC2019'd 30 0 0 0 3 3 3 
4 '15DEC2019'd 40 0 0 0 0 0 0
5 '10DEC2019'd 50 0 0 0 0 0 0
6 '15DEC2019'd 60 0 0 0 0 0 0
7 '15DEC2019'd 70 0 0 0 0 0 0
8 '15DEC2019'd 80 0 0 0 0 0 0
9 '10DEC2019'd 90 0 7 8 9 9 9
10 '10DEC2019'd 100 0 0 0 0 0 0
;

data dates;
	input date:date9.;
	datalines;
20NOV2019
25NOV2019
02DEC2019
05DEC2019
10DEC2019
15DEC2019
;

data _null_;
set dates end=done;
if _n_ = 1 then call execute('data b; set a;');
call execute(
'if offer_date = ' !! put(date,5.) !! ' then accum_loan = accumtill_' !! put(date,date9.) !! ';'
);
if done then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 07:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-multiple-IF-statements-for-each-argument-in-VaRList-macro/m-p/617144#M180787</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-14T07:22:07Z</dc:date>
    </item>
  </channel>
</rss>

