<?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: Create a DATASET for the First iteration  in a Do Loop. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822136#M324614</link>
    <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Since i am not Well versed with SAS Arrays, i m trying to use SAS Macros as i need to calculate other variables and generating various reports.&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;S.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2022 19:32:26 GMT</pubDate>
    <dc:creator>Santt0sh</dc:creator>
    <dc:date>2022-07-07T19:32:26Z</dc:date>
    <item>
      <title>Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822128#M324607</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a Data set using a Do loop in Macro program for the first iteration or at the beginning of the Iteration.&lt;/P&gt;&lt;P&gt;i = 1 can be&amp;nbsp; 0,3,4,5, or any number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly Suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data Sales;
Name $ Product $ Sales1 Sales2 Sales3;
datalines;
aaa xxxxx 0 0 200
dfrt iiiiiiiii 03 05 65
ertttt pxxdfd 55 0 0
;

/*START OF MACRO*/
%macro dsn(t=,NME=);
%let cnt = %sysfunc(countw(&amp;amp;t.));
	%do i = 1 %to &amp;amp;cnt.;
		%let v&amp;amp;i. = %sysfunc(scan(&amp;amp;t.,&amp;amp;i.));
				%put &amp;amp;&amp;amp;v&amp;amp;i.;
			%if %trim(&amp;amp;&amp;amp;v&amp;amp;i.) ne 0 /*OR %trim(&amp;amp;&amp;amp;v&amp;amp;i.) NE %str()*/  %then %do;
				%let ite =&amp;amp;i.;
				%put 	valueM&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;amp;&amp;amp;v&amp;amp;i.;
				%put 	SLS&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; SLS_&amp;amp;i.;
/*IM TRYING TO CREATE THE DATASET WHERE SALES IS NOT 0*/
				data SLS_&amp;amp;ite.;    
					SLS_&amp;amp;ite. = &amp;amp;&amp;amp;v&amp;amp;i.;
				run;
			%end;
/* THE ELSE; IS ONLY PUTTING SALES 0 VALUES FOR THE PRODUCTS*/
			%else %do;
				%let ite = %sysevalf (&amp;amp;i. + 1);
				%put cnt&amp;amp;ite.===&amp;gt;&amp;gt; &amp;amp;&amp;amp;ite.; 
				%let v&amp;amp;ite. = %sysfunc(scan(&amp;amp;t.,&amp;amp;ite.));
				%put &amp;amp;&amp;amp;v&amp;amp;ite.;
				%put 	SLS&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt;SLS_&amp;amp;ite.;
				%put 	VALUE&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;amp;&amp;amp;v&amp;amp;ite.;
			%end;	
	%end;
%mend;
%dsn(t=0 0 10, SALES1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2022 19:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822128#M324607</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T19:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822132#M324611</link>
      <description>You sure you shouldn't be using arrays here?</description>
      <pubDate>Thu, 07 Jul 2022 19:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822132#M324611</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-07T19:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822134#M324613</link>
      <description>Hi Reeza,&lt;BR /&gt;Thank you for your quick response!&lt;BR /&gt;&lt;BR /&gt;I am not well versed with Arrays, and this program will be used across the department to measure sales, invoices and stocks etc.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2022 19:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822134#M324613</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T19:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822136#M324614</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Since i am not Well versed with SAS Arrays, i m trying to use SAS Macros as i need to calculate other variables and generating various reports.&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;S.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 19:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822136#M324614</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T19:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822138#M324616</link>
      <description>&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays are pretty basic and very likely worth the effort to learn. Much easier, cleaner and simpler than macros to work with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 19:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822138#M324616</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-07T19:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822139#M324617</link>
      <description>&lt;P&gt;And what is the OUTPUT you expect to get for that INPUT?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 19:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822139#M324617</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-07T19:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822151#M324625</link>
      <description>Hi Reeza,&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response!&lt;BR /&gt;I am trying to create a new dataset for the first iteration where i NE 0.&lt;BR /&gt;Which should be the first I NE 0&lt;BR /&gt;&lt;BR /&gt;As Discussed earlier the macro will eliminate the 0's and count it will be basically I+1 when we find a 0 in the macro variables passed&lt;BR /&gt;Something like this for the first iteration&lt;BR /&gt;Data sales1;&lt;BR /&gt;Set &amp;amp;dsn;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2022 20:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822151#M324625</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T20:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822153#M324627</link>
      <description>%dsn(t=0 0 10, NME= SALES1);</description>
      <pubDate>Thu, 07 Jul 2022 20:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822153#M324627</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T20:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822154#M324628</link>
      <description>&lt;P&gt;I think you're responding to Tom not me, but I have the same question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain your input, expected output and the logic, otherwise we're very likely dealing with an &lt;A href="https://xyproblem.info/" target="_self"&gt;xy problem&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And before you write macros you should have a working non macro version, can you show that for your use case please.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 21:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822154#M324628</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-07T21:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822162#M324632</link>
      <description>&lt;BR /&gt;I am trying to create a new dataset for the first iteration where i NE 0.&lt;BR /&gt;Which should be the first I NE 0&lt;BR /&gt;&lt;BR /&gt;As Discussed earlier the macro will eliminate the 0's and count it will be basically I+1 when we find a 0 in the macro variables passed&lt;BR /&gt;Something like this for the first iteration&lt;BR /&gt;Data sales_&amp;amp;I.;&lt;BR /&gt;Set &amp;amp;nme.;&lt;BR /&gt;Run;&lt;BR /&gt;%dsn(t=0 0 10, NME= SALES1);&lt;BR /&gt;&lt;BR /&gt;Copy of the dataset Sales1. Using the first dataset created i will calculating few other variables.&lt;BR /&gt;&lt;BR /&gt;INPUT:&lt;BR /&gt;&lt;BR /&gt;Data Sales1;&lt;BR /&gt;Name $ Product $ Sales1 Sales2 Sales3;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa xxxxx 0 0 200&lt;BR /&gt;dfrt iiiiiiiii 03 05 65&lt;BR /&gt;ertttt pxxdfd 55 0 0&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;Required OUTPUT.&lt;BR /&gt;Data Sales_1;&lt;BR /&gt;set sales1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2022 21:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822162#M324632</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T21:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822166#M324636</link>
      <description>Hi Reeza,&lt;BR /&gt;&lt;BR /&gt;I have a piece of code without macro:&lt;BR /&gt;&lt;BR /&gt;When i = 2;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;DATA sales_1;&lt;BR /&gt;SET sales;&lt;BR /&gt;ELEsales =MAX(1-numberofpymnts,0);&lt;BR /&gt;RUN;&lt;BR /&gt;/*calculate the commision, roi any taxes paid*/&lt;BR /&gt;DATA sales_ELEGBLE;&lt;BR /&gt;SET ales_1;&lt;BR /&gt;IF ELEsales = 1 ;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Jul 2022 21:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822166#M324636</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-07T21:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822180#M324644</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183704"&gt;@Santt0sh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a rule of thumb:&lt;/P&gt;
&lt;P&gt;1. Only use SAS Macro language if you can't do it with normal Base SAS language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Always first develop a working macro free script for one use case before you make things dynamic using macro code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading through this discussion it's still not clear to me what you have and what you need. But I believe it's very likely that no macro code will be required (which keeps things "simple").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you post:&lt;/P&gt;
&lt;P&gt;1. Representative sample data via a fully working SAS data step (Have) - something like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input Name $ Product $ Sales1 Sales2 Sales3;
  datalines;
aaa xxxxx 0 0 200
dfrt iiiiiiiii 03 05 65
ertttt pxxdfd 55 0 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Show us how the desired result based on the sample data provided needs to look like (Want)&lt;/P&gt;
&lt;P&gt;3. Explain the business logic required to get from the Have to the Want table.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 00:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822180#M324644</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-08T00:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822190#M324648</link>
      <description>Thank you Reeza!&lt;BR /&gt;As we are not sure about i = , if has different values for eg.&lt;BR /&gt;%dsn(t=1 200 100 0 20 0 0, NME= SALES1);&lt;BR /&gt;&lt;BR /&gt;Then our results will be wrong and I only want to create a dataset only for the first iteration i.e.&lt;BR /&gt;i = ;&lt;BR /&gt;&lt;BR /&gt;I was thinking&lt;BR /&gt;Do loop %Do j = 1% to 1;&lt;BR /&gt;data sales&amp;amp;j.;&lt;BR /&gt;set &amp;amp;dsn.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;S&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Jul 2022 02:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822190#M324648</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-08T02:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822194#M324649</link>
      <description>&lt;P&gt;So this first sentence does not make any sense.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I am trying to create a Data set using a Do loop in Macro program for the first iteration or at the beginning of the Iteration.&lt;/P&gt;
&lt;P&gt;i = 1 can be&amp;nbsp; 0,3,4,5, or any number.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;By I=1 do you mean an ASSIGNMENT statement to set a variable named I to the value 0 ?&lt;/P&gt;
&lt;P&gt;If so then what does 0,3,4,5 mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you trying to mimic the behavior of the data set DO statement where you could write something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do i=1,0,3,4,5 ;
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And create a dataset like:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1657246518687.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73048i157DAF1022D42396/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1657246518687.png" alt="Tom_0-1657246518687.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then put the list of values as SPACE delimited, or any delimiter other than a comma, and use another variable to index into the list of values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=0 1 3 4 5;
%do index=1 to %sysfunc(countw(&amp;amp;list,%str( ));
  %let next=%scan(&amp;amp;list,&amp;amp;index,%str( ));
%*  other macro statements that do something with &amp;amp;NEXT ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you could make a macro that takes LIST as an input parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mymacro(list=0 1 3 4 5)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if the question is how to test if a macro variable's value is equal to 0 don't make it so complicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;next = 0 %then %do;
....
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you worry that the macro variable might some strange characters that cause the condition to be misunderstood by the macro processor then adds some quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;next" = "0" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or some macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %superq(next) = 0 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 02:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822194#M324649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-08T02:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822199#M324653</link>
      <description>Hi Tom,&lt;BR /&gt;Thank you for your quick response.&lt;BR /&gt;I have followed similar steps,&lt;BR /&gt;&lt;BR /&gt;Data Sales;&lt;BR /&gt;Name $ Product $ Sales1 Sales2 Sales3;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa xxxxx 0 0 200&lt;BR /&gt;dfrt iiiiiiiii 03 05 65&lt;BR /&gt;ertttt pxxdfd 55 0 0&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;/*START OF MACRO*/&lt;BR /&gt;%macro dsn(t=,NME=);&lt;BR /&gt;%let cnt = %sysfunc(countw(&amp;amp;t.));&lt;BR /&gt;%do i = 1 %to &amp;amp;cnt.;&lt;BR /&gt;%let v&amp;amp;i. = %sysfunc(scan(&amp;amp;t.,&amp;amp;i.));&lt;BR /&gt;%put &amp;amp;&amp;amp;v&amp;amp;i.;&lt;BR /&gt;%if %trim(&amp;amp;&amp;amp;v&amp;amp;i.) ne 0 /*OR %trim(&amp;amp;&amp;amp;v&amp;amp;i.) NE %str()*/ %then %do;&lt;BR /&gt;%let ite =&amp;amp;i.;&lt;BR /&gt;%put valueM&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;amp;&amp;amp;v&amp;amp;i.;&lt;BR /&gt;%put SLS&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; SLS_&amp;amp;i.;&lt;BR /&gt;/*IM TRYING TO CREATE THE DATASET WHERE SALES IS NOT 0*/&lt;BR /&gt;data SLS_&amp;amp;ite.;&lt;BR /&gt;SLS_&amp;amp;ite. = &amp;amp;&amp;amp;v&amp;amp;i.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;/* THE ELSE; IS ONLY PUTTING SALES 0 VALUES FOR THE PRODUCTS*/&lt;BR /&gt;%else %do;&lt;BR /&gt;%let ite = %sysevalf (&amp;amp;i. + 1);&lt;BR /&gt;%put cnt&amp;amp;ite.===&amp;gt;&amp;gt; &amp;amp;&amp;amp;ite.;&lt;BR /&gt;%let v&amp;amp;ite. = %sysfunc(scan(&amp;amp;t.,&amp;amp;ite.));&lt;BR /&gt;%put &amp;amp;&amp;amp;v&amp;amp;ite.;&lt;BR /&gt;%put SLS&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt;SLS_&amp;amp;ite.;&lt;BR /&gt;%put VALUE&amp;amp;i.====&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;amp;&amp;amp;v&amp;amp;ite.;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%dsn(t= 0 0 10, SALES1);&lt;BR /&gt;&lt;BR /&gt;The above code ignores the 0 and i becomes i+1 when it finds a non zero.&lt;BR /&gt;&lt;BR /&gt;for example %dsn(t= 0 40 14, SALES1);&lt;BR /&gt;MLOGIC(BTL_DETAILS): %DO loop index variable I is now 2; loop will iterate again.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;MLOGIC(BTL_DETAILS): %LET (variable name is V2)&lt;BR /&gt;SYMBOLGEN: Macro variable T resolves to 0 40 14 14&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;MLOGIC(BTL_DETAILS): %PUT &amp;amp;&amp;amp;V&amp;amp;i.&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;SYMBOLGEN: Macro variable V2 resolves to 40&lt;BR /&gt;40&lt;BR /&gt;MLOGIC(TRIM): Beginning execution.&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;SYMBOLGEN: Macro variable V2 resolves to 40&lt;BR /&gt;MLOGIC(TRIM): Parameter VALUE has value 40&lt;BR /&gt;MLOGIC(TRIM): %LOCAL I&lt;BR /&gt;SYMBOLGEN: Macro variable VALUE resolves to 40&lt;BR /&gt;&lt;BR /&gt;now 40 is value for SALE3 , if i assign the value of SALE3 to i = 1 then it will be an issue reports&lt;BR /&gt;&lt;BR /&gt;hence i want to create a dataset when i value is not 0 and we are not sure how many values will be there and in which order with 0's or without 0's.&lt;BR /&gt;&lt;BR /&gt;Apologies for any confusion created.&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Jul 2022 02:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822199#M324653</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-07-08T02:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822200#M324654</link>
      <description>&lt;P&gt;Simplify, Simplify, Simplify&lt;/P&gt;
&lt;P&gt;Simplify, Simplify&lt;STRIKE&gt;, Simplify&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;Simplify&lt;STRIKE&gt;, Simplify, Simplify&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with a simple macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dsn(t=,NME=);
%local cnt i value ;
%let cnt = %sysfunc(countw(&amp;amp;t.,%str( )));
%do i = 1 %to &amp;amp;cnt.;
  %let value = %scan(&amp;amp;t,&amp;amp;i,%str( ));
  %if &amp;amp;value ne 0 %then %do;
     %put &amp;amp;=value is not zero ;
  %end;
  %else %do;
     %put &amp;amp;=value is zero ;
  %end;
%end;
%mend;
%dsn(t= 0 0 10,nme=SALES1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;36   %dsn(t= 0 0 10,nme=SALES1);
VALUE=0 is zero
VALUE=0 is zero
VALUE=10 is not zero
&lt;/PRE&gt;
&lt;P&gt;Things to fix.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Be explicit about which macro variables are LOCAL to this macro&lt;/LI&gt;
&lt;LI&gt;Be explicit about what is the delimiter for COUNTW() and %SCAN() function calls.&lt;/LI&gt;
&lt;LI&gt;Do not use %SYSFUNC() to call a data step function to do something you can do with a macro function.&lt;/LI&gt;
&lt;LI&gt;Never use the SAS autocall %TRIM() macro. I have never seen a valid use case for this macro and definitely not in a case like this that does not involve any character that require the use of macro quoting.&lt;/LI&gt;
&lt;LI&gt;You cannot pass a value in a macro call by position if the parameter is defined in the %MACRO statement to require that it be passed by name. (you can do the reverse: pass by name a parameter this is defined to allow the value to be passed by position)
&lt;UL&gt;
&lt;LI&gt;And if you do pass any values by position they have to come before all values that are passed by name.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Now that we have a framework for looping over a list of values and testing if any of them is zero can you please explain what SAS code you are trying to use the macro to generate?&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;What is the purpose of the values passed in the T parameter?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;What is the purpose of the value passed in the NME parameter&lt;/LI&gt;
&lt;LI&gt;What is it that you want to do differently when the next T value is zero than when it is not zero?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 04:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822200#M324654</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-08T04:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create a DATASET for the First iteration  in a Do Loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822210#M324659</link>
      <description>&lt;P&gt;Let's make this simple.&lt;/P&gt;
&lt;P&gt;You have a dataset looking like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Sales;
Name $ Product $ Sales1 Sales2 Sales3;
datalines;
aaa xxxxx 0 0 200
dfrt iiiiiiiii 03 05 65
ertttt pxxdfd 55 0 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you want to get out of this? A report, a dataset, or multiple reports/datasets?&lt;/P&gt;
&lt;P&gt;Just show the end result, then we can go looking for the tools that are best.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 05:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-DATASET-for-the-First-iteration-in-a-Do-Loop/m-p/822210#M324659</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-08T05:57:21Z</dc:date>
    </item>
  </channel>
</rss>

