<?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: How to pass multiple values to a variable in data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621741#M182828</link>
    <description>Thanks, I would like to slightly tweak the question now. What are the&lt;BR /&gt;different ways to pass multiple values to a variable in data step?&lt;BR /&gt;</description>
    <pubDate>Sun, 02 Feb 2020 08:58:12 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-02-02T08:58:12Z</dc:date>
    <item>
      <title>How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621737#M182825</link>
      <description>&lt;P&gt;Assume I have a variable called FLAG (character variable) for which I have to pass values as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A. First 10 obs should have value 'O'&lt;/P&gt;
&lt;P&gt;B. Next 10 obs should have value 'MODO'&lt;/P&gt;
&lt;P&gt;C. Last 10 instead should have missing values ' '&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;E.g.&lt;/P&gt;
&lt;P&gt;FLAG&lt;/P&gt;
&lt;P&gt;O&lt;/P&gt;
&lt;P&gt;O&lt;/P&gt;
&lt;P&gt;O&lt;/P&gt;
&lt;P&gt;..&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;MODO&lt;/P&gt;
&lt;P&gt;MODO&lt;/P&gt;
&lt;P&gt;..&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help in providing me the data step for this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 08:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621737#M182825</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-02T08:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621738#M182826</link>
      <description>&lt;P&gt;Use the automatic variable _N_ to determine the number of the current observation. Take care to set a proper length for your new variable.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 08:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621738#M182826</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-02T08:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621741#M182828</link>
      <description>Thanks, I would like to slightly tweak the question now. What are the&lt;BR /&gt;different ways to pass multiple values to a variable in data step?&lt;BR /&gt;</description>
      <pubDate>Sun, 02 Feb 2020 08:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621741#M182828</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-02T08:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621742#M182829</link>
      <description>&lt;P&gt;You can use a series of if-then-else-if, a select() block, or a format. If you have lots of values to load dynamically from data, a hash object can be the tool of choice.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 09:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621742#M182829</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-02T09:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621748#M182832</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example, you are not passing any variables to a new variable. You are creating a new variable not depending on any variables present in the input data set. only the current observation's position, so a different sorting of the same input would yield different results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;says, the position can be obtained from the input counter _N_. Note that it is necessary to declare the FLAG variable with a length = 4, because it is given the value 'O' with a length = 1 in the first iteration, so the value 'MODO' would be truncated to 'M' in obs. 11-20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend that you get yourself a copy of "The little SAS book". It is an excellent introduction that takes you all the way from newbie to a SAS programmer ready to take on most problems in day-to-day work. Excerpt here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/content/dam/SAS/support/en/books/the-little-sas-book-a-primer-fifth-edition/65423_excerpt.pdf" target="_blank"&gt;https://support.sas.com/content/dam/SAS/support/en/books/the-little-sas-book-a-primer-fifth-edition/65423_excerpt.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have; 
 	do dummy = 1 to 50; output; end;
run;
data want; set have;
	length flag $4;
	if _N_ &amp;lt;= 10 then flag = 'O';
	else if _N_ &amp;lt;= 20 then flag = 'MODO';
	else flag = '';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Feb 2020 10:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621748#M182832</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-02-02T10:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621791#M182846</link>
      <description>&lt;P&gt;Variables are not stored independent from datasets.&amp;nbsp;Are taking about creating a NEW dataset?&amp;nbsp; Or adding a new variable to an existing dataset?&lt;/P&gt;
&lt;P&gt;Here is straight forward translation of your rules into a data step to create a dataset named WANT with a variable named FLAG.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length flag $4 ;
  flag='O';
  do i=1 to 10; output; end;
  flag='MONO';
  do i=1 to 10; output; end;
  flag=' ';
  do i=1 to 10; output; end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 17:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621791#M182846</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-02T17:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621792#M182847</link>
      <description>I talked about adding a new variable in the existing dataset.</description>
      <pubDate>Sun, 02 Feb 2020 17:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621792#M182847</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-02-02T17:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass multiple values to a variable in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621795#M182849</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I talked about adding a new variable in the existing dataset.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So if you are starting with an existing dataset then you will want to make a new dataset that has the new values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  row+1;
  length flag $4;
  if 1 &amp;lt;= row &amp;lt;=10 then flag='O';
  else if row &amp;lt;=20 then flag='MONO';
  else if row &amp;lt;=30 then flag=' ';
  else flag=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you do if the dataset has 50 observations instead of 30?&amp;nbsp; What if it has only 10 observations?&amp;nbsp; Is there some variable in the existing dataset that can be used to determine how to set the new FLAG variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Feb 2020 17:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-multiple-values-to-a-variable-in-data-step/m-p/621795#M182849</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-02T17:52:21Z</dc:date>
    </item>
  </channel>
</rss>

