<?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 Re: Macro loop in a data step_HELP NEEDED in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529981#M5621</link>
    <description>Hi,&lt;BR /&gt;Thats right.&lt;BR /&gt;But I need to place this rule into The macro loop from The first code.&lt;BR /&gt;And I have no idea how to do this&lt;BR /&gt;SH&lt;BR /&gt;</description>
    <pubDate>Fri, 25 Jan 2019 07:48:18 GMT</pubDate>
    <dc:creator>siahal</dc:creator>
    <dc:date>2019-01-25T07:48:18Z</dc:date>
    <item>
      <title>Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529834#M5608</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I kindly ask for a help with one issue.&lt;/P&gt;&lt;P&gt;While dealing with a macro loop in a data step i have a problem with app_number_of_children variable in prod_sorted table.&lt;/P&gt;&lt;P&gt;Despite the condition 'not missing(app_number_of_children) and app_number_of_children&amp;lt;1', and expected result 1 in wyj.vin_kat, there is value 3 apearing all the time.&lt;/P&gt;&lt;P&gt;As i can understand, the macro loop rewrite the value after each iteration.&lt;/P&gt;&lt;P&gt;How can I avoid it and get the right value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	%global test;
	proc sql noprint;
		select warunek into :test separated by ' X'	
		from wyj.warunek order by warunek;
	quit;
	
	proc sql noprint; 
		select count(*) into :ile_war	
		from wyj.warunek; 
	quit;&lt;/PRE&gt;&lt;PRE&gt;%macro kategoryzuj;
	data wyj.vin_kat;	
		set wyj.prod_sorted;
			%do a=1 %to &amp;amp;ile_war;
				%let war = %scan(%scan(&amp;amp;test,&amp;amp;a,'X'),3,'A');
				%let zmien = %scan(%scan(&amp;amp;test,&amp;amp;a,'X'),1,'A');
				%let wart = %scan(%scan(&amp;amp;test,&amp;amp;a,'X'),2,'A');
				if &amp;amp;war then &amp;amp;zmien = &amp;amp;wart;
			%end;
		output;
	end; 
	run;

%mend;
%kategoryzuj;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 20:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529834#M5608</guid>
      <dc:creator>siahal</dc:creator>
      <dc:date>2019-01-24T20:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529840#M5609</link>
      <description>&lt;P&gt;Run your macro with the options mprint and examine the code generated to see if the generated code is as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint;&lt;/P&gt;
&lt;P&gt;%kategoryzuj;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 20:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529840#M5609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-24T20:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529861#M5612</link>
      <description>&lt;P&gt;Thanks for your advice&lt;/P&gt;&lt;P&gt;but i still can't get an idea what to do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	data vin_kat;	
		set wyj.vin;
		if not missing(app_number_of_children) and app_number_of_children &amp;lt;= 0 then app_number_of_children = 1;
		if 0 &amp;lt; app_number_of_children &amp;lt;= 1 then app_number_of_children = 2;
		if 1 &amp;lt; app_number_of_children then app_number_of_children = 3;
		output;
	run;&lt;/PRE&gt;&lt;P&gt;the question is - what will be outputed to the data set?&lt;/P&gt;&lt;P&gt;i get 3 in all observations.&lt;/P&gt;&lt;P&gt;If I have 0 before running the data step, the first condition changes it to 1, the second condition - to 2, and the last one - to 3.&lt;/P&gt;&lt;P&gt;It overwrites itself and the outputs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have an idea how to apply only one condition - the right one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SH&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 20:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529861#M5612</guid>
      <dc:creator>siahal</dc:creator>
      <dc:date>2019-01-24T20:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529897#M5614</link>
      <description>&lt;P&gt;What are you trying to do?&lt;/P&gt;
&lt;P&gt;Explain with a simple example using actual data. Post the data as a simple data step that either set values as constants or reads from in-line data.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 22:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529897#M5614</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-24T22:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529930#M5616</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257516"&gt;@siahal&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your advice&lt;/P&gt;
&lt;P&gt;but i still can't get an idea what to do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	data vin_kat;	
		set wyj.vin;
		if not missing(app_number_of_children) and app_number_of_children &amp;lt;= 0 then app_number_of_children = 1;
		if 0 &amp;lt; app_number_of_children &amp;lt;= 1 then app_number_of_children = 2;
		if 1 &amp;lt; app_number_of_children then app_number_of_children = 3;
		output;
	run;&lt;/PRE&gt;
&lt;P&gt;the question is - what will be outputed to the data set?&lt;/P&gt;
&lt;P&gt;i get 3 in all observations.&lt;/P&gt;
&lt;P&gt;If I have 0 before running the data step, the first condition changes it to 1, the second condition - to 2, and the last one - to 3.&lt;/P&gt;
&lt;P&gt;It overwrites itself and the outputs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have an idea how to apply only one condition - the right one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;SH&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect that you want ELSE in the code. Currently all 3 of your if statements are being evaluated and you see the result from the last one. Trace the logic: suppose the value is &amp;lt;=0, then the first if assigs value of 1, then the next if, since 1 &amp;lt;=1 reassigs to 2, then the last if assigns 3 because the 2 just assigned is &amp;gt;1.&lt;/P&gt;
&lt;P&gt;If the value starts at between 0 and 1 then the first If doesn't execute but the second does setting 2 and then again the last sees the 2 and reassigns to 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data vin_kat;	
		set wyj.vin;
		if not missing(app_number_of_children) and app_number_of_children &amp;lt;= 0 then app_number_of_children = 1;
		&lt;STRONG&gt;else&lt;/STRONG&gt; if 0 &amp;lt; app_number_of_children &amp;lt;= 1 then app_number_of_children = 2;
		&lt;STRONG&gt;else&lt;/STRONG&gt; if 1 &amp;lt; app_number_of_children then app_number_of_children = 3;
		output;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2019 00:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529930#M5616</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-25T00:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529981#M5621</link>
      <description>Hi,&lt;BR /&gt;Thats right.&lt;BR /&gt;But I need to place this rule into The macro loop from The first code.&lt;BR /&gt;And I have no idea how to do this&lt;BR /&gt;SH&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Jan 2019 07:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/529981#M5621</guid>
      <dc:creator>siahal</dc:creator>
      <dc:date>2019-01-25T07:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop in a data step_HELP NEEDED</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/530011#M5634</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem has been solved by dividing the data set by variables and conditions, checking separately and merging together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks to all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro kategoryzuj;

%global test;
%put &amp;amp;test;

	proc sql noprint; 
		select count(*) into :ile_war	
		from wyj.warunek; 
	quit;
%put &amp;amp;ile_war;

proc sql noprint;
select zmienna into :zmien_kat separated by " "
from wyj.lista_zmiennych_il;
quit;

proc sql noprint;
select count(zmienna) into :count_zm
from wyj.lista_zmiennych_il;
quit;

	data wyj.vin_kat;	
	set wyj.vin (keep = aid fin_period vin1 vin2 vin3);
	run;

%do c=1 %to &amp;amp;count_zm;

%let zmien = %scan(&amp;amp;zmien_kat,&amp;amp;c," ");
%put &amp;amp;zmien;

data t.warunek_iter;
set t.warunek;
zmienna = lowcase(trim(left(zmienna)));
run;

data t.warunek_iter;
set t.warunek_iter;
where zmienna = "&amp;amp;zmien";
run;

	proc sql noprint;
		select warunek into :test separated by ' X'	
		from wyj.warunek_iter order by warunek;
		quit;

	proc sql noprint;
	select count (*) into :iter
	from wyj.warunek_iter;
	quit;

	
	%do i = 1 %to &amp;amp;iter;

	%let war = %scan(%scan(&amp;amp;test,&amp;amp;i,'X'),3,'A');
	%let wart = %scan(%scan(&amp;amp;test,&amp;amp;i,'X'),2,'A');

	data war&amp;amp;c._&amp;amp;i;
	set wyj.vin (keep = aid &amp;amp;zmien);
	where &amp;amp;war;
	run;

	data war&amp;amp;c._&amp;amp;i;
	set war&amp;amp;c._&amp;amp;i;
	if &amp;amp;war then &amp;amp;zmien = &amp;amp;wart;
	run;

	%end;

	data war_&amp;amp;c;
	length aid $16;
	length &amp;amp;zmien 8;
	delete;
	run;

	%do j=1 %to &amp;amp;iter;

	data war_&amp;amp;c;
	set war_&amp;amp;c war&amp;amp;c._&amp;amp;j;
	run;

	%end;

proc sort data = war_&amp;amp;c;
by aid;
run;

proc sort data = wyj.vin_kat;
by aid;
run;

data wyj.vin_kat;
merge wyj.vin_kat(in=z) war_&amp;amp;c;		
	by aid;		
	if z;	
run;


%end;




%mend;

%kategoryzuj;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Jan 2019 11:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-loop-in-a-data-step-HELP-NEEDED/m-p/530011#M5634</guid>
      <dc:creator>siahal</dc:creator>
      <dc:date>2019-01-25T11:04:34Z</dc:date>
    </item>
  </channel>
</rss>

