<?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: Using array and do loop to create multiple new variables conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-array-and-do-loop-to-create-multiple-new-variables/m-p/745039#M233496</link>
    <description>&lt;P&gt;The way SAS works for most data step operations you create the variable. Period. Conditionally you assign values to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, which variables are the "new" variables?&lt;/P&gt;
&lt;P&gt;The code you posted will not run but generate an a "unclosed DO" because there is no "End; " statement to close the "do i=1 to dim(new);"&lt;/P&gt;
&lt;P&gt;Also, to assign values to multiple variables generally you need, if that is what this is supposed to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;	if patient="JOHNDOE" then gender=1 and job=1;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should be:&lt;/P&gt;
&lt;PRE&gt;if patient ="JOHNDOE" then do;
    gender = 1;
   job = 1;
end;&lt;/PRE&gt;
&lt;P&gt;Did you read the log when submitting that code?&lt;/P&gt;
&lt;P&gt;Something like "gender=1 and job=1" will attempt to return the value of the comparison: is gender=1 and job=1.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 20:56:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-06-01T20:56:37Z</dc:date>
    <item>
      <title>Using array and do loop to create multiple new variables conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-and-do-loop-to-create-multiple-new-variables/m-p/745038#M233495</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to add two new variables to a dataset based on one condition. I believe I need to use an array and a do loop (?). Below is the code I have tried thus far but the resulting dataset does not output a 1 for both of my new variables when it should. I am new to SAS so any help is very much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
	array new(*) patient;
		gender=0;
		job=0;
	do i=1 to dim(new);
	if patient="JOHNDOE" then gender=1 and job=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Jun 2021 20:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-and-do-loop-to-create-multiple-new-variables/m-p/745038#M233495</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-06-01T20:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using array and do loop to create multiple new variables conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-and-do-loop-to-create-multiple-new-variables/m-p/745039#M233496</link>
      <description>&lt;P&gt;The way SAS works for most data step operations you create the variable. Period. Conditionally you assign values to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, which variables are the "new" variables?&lt;/P&gt;
&lt;P&gt;The code you posted will not run but generate an a "unclosed DO" because there is no "End; " statement to close the "do i=1 to dim(new);"&lt;/P&gt;
&lt;P&gt;Also, to assign values to multiple variables generally you need, if that is what this is supposed to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;	if patient="JOHNDOE" then gender=1 and job=1;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should be:&lt;/P&gt;
&lt;PRE&gt;if patient ="JOHNDOE" then do;
    gender = 1;
   job = 1;
end;&lt;/PRE&gt;
&lt;P&gt;Did you read the log when submitting that code?&lt;/P&gt;
&lt;P&gt;Something like "gender=1 and job=1" will attempt to return the value of the comparison: is gender=1 and job=1.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 20:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-and-do-loop-to-create-multiple-new-variables/m-p/745039#M233496</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-01T20:56:37Z</dc:date>
    </item>
  </channel>
</rss>

