<?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 syntax for if/then assignment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675379#M203482</link>
    <description>&lt;P&gt;How to set code "Y" if ABC = "R" else set to "N".&lt;/P&gt;</description>
    <pubDate>Sat, 08 Aug 2020 13:05:06 GMT</pubDate>
    <dc:creator>tathagatab</dc:creator>
    <dc:date>2020-08-08T13:05:06Z</dc:date>
    <item>
      <title>syntax for if/then assignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675379#M203482</link>
      <description>&lt;P&gt;How to set code "Y" if ABC = "R" else set to "N".&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 13:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675379#M203482</guid>
      <dc:creator>tathagatab</dc:creator>
      <dc:date>2020-08-08T13:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675380#M203483</link>
      <description>&lt;P&gt;newvar = ifc(abc='R', 'Y', 'N');&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 12:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675380#M203483</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2020-08-08T12:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for if/then assignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675382#M203485</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1j60arf27ll4nn1ejavv3nby4pa.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;IF-THEN/ELSE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 13:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675382#M203485</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-08T13:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: syntax for if/then assignment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675383#M203486</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/340596"&gt;@tathagatab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How to set code "Y" if ABC = "R" else set to "N".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The way to set a value to a variable is called an assignment statement.&amp;nbsp; But you don't say what variable you want set to Y.&amp;nbsp; Let's assume it is called CODE.&amp;nbsp; So you are talking about two assignment statements like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;code = 'Y';
code = 'N';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The way to conditionally run any statement is the IF/THEN/ELSE structure.&amp;nbsp; So you want to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if abc= 'R' then code = 'Y';
else code = 'N';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will need to use these statements in a data step.&amp;nbsp; So assuming your current dataset is named HAVE you can use this step to make a new dataset named WANT with the new CODE variable created.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if abc= 'R' then code = 'Y';
  else code = 'N';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 13:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675383#M203486</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-08T13:15:23Z</dc:date>
    </item>
    <item>
      <title>SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675405#M203805</link>
      <description>&lt;P&gt;HOW TO WRITE CODE IN NEW VARUABLE ABC: If Y = 'Z'&amp;nbsp; WHERE x = ‘o' then set to set to = 'Z' ; else if Y not missing where x = ‘o' then set to "L"; else if ARM not missing then set to "R". RUN;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 16:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675405#M203805</guid>
      <dc:creator>tathagatab</dc:creator>
      <dc:date>2020-08-08T16:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675412#M203806</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/340596"&gt;@tathagatab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;HOW TO WRITE CODE IN NEW VARUABLE ABC: If Y = 'Z'&amp;nbsp; WHERE x = ‘o' then set to set to = 'Z' ; else if Y not missing where x = ‘o' then set to "L"; else if ARM not missing then set to "R". RUN;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I sounds like you want to determine what value to assign to ABC based on the values of Y and X and ARM.&amp;nbsp; Is that correct?&lt;/P&gt;
&lt;P&gt;You list three combinations to check that do not cover all possible situations.&amp;nbsp; Are there any records that do not fall into one of those categories?&amp;nbsp; What do you want to set ABC to in those cases?&amp;nbsp; Do you just want to leave it alone?&amp;nbsp; If it is a new variable then it will be set to ' '.&amp;nbsp; &amp;nbsp;Also if ABC is a new variable you really should tell SAS how to create it. Otherwise SAS will guess based on how it is first used.&amp;nbsp; So if ABC could ever have values that take more than one byte you would need to define it before the code that sets it to 'Z'. Otherwise SAS will guess you want to define it as length $1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length abc $1;
  if y='Z' and x='o' then ABC='Z';
  else if not missing(y) and x='o' then ABC = 'L';
  else if not missing(arm) then ABC='R';
  else ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Aug 2020 17:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/675412#M203806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-08T17:06:58Z</dc:date>
    </item>
    <item>
      <title>How to write code in   DATA SET =XYZ if a = "B" THEN X =  "Y" ;  if a ne."B" THEN set X =   "N" ;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676094#M203807</link>
      <description>&lt;P&gt;How to write code in &amp;nbsp;&amp;nbsp;DATA SET =XYZ&lt;/P&gt;&lt;P&gt;if a = "B" THEN X =&amp;nbsp; "Y" ;&lt;/P&gt;&lt;P&gt;if a ne."B" THEN set X =&amp;nbsp;&amp;nbsp; "N" ;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 08:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676094#M203807</guid>
      <dc:creator>tathagatab</dc:creator>
      <dc:date>2020-08-12T08:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write code in   DATA SET =XYZ if a = "B" THEN X =  "Y" ;  if a ne.&amp;qu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676095#M203808</link>
      <description>Could you please provide a sample and expected output</description>
      <pubDate>Wed, 12 Aug 2020 08:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676095#M203808</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-08-12T08:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to write code in   DATA SET =XYZ if a = "B" THEN X =  "Y" ;  if a ne.&amp;qu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676096#M203809</link>
      <description>&lt;P&gt;See if you can use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   a = "A"; output;
   a = "B"; output;
run;

data want;
   set have;
   if a = "B" then x = "Y";
   else            x = "N";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Aug 2020 08:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676096#M203809</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-08-12T08:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: SYNTAX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676097#M203810</link>
      <description>&lt;P&gt;Please stop pestering us with near-identical questions about the same issue; instead study the answers given, and ask proper follow-up questions in the same thread.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 08:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676097#M203810</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-12T08:58:14Z</dc:date>
    </item>
    <item>
      <title>HOW TO SELECT  to time part of A   where B = ("C" and "D")</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676520#M204008</link>
      <description>&lt;P&gt;HOW TO SELECT &amp;nbsp;to time part of A &amp;nbsp;&amp;nbsp;where B = ("C" and "D")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 15:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676520#M204008</guid>
      <dc:creator>tathagatab</dc:creator>
      <dc:date>2020-08-13T15:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO SELECT  to time part of A   where B = ("C" and "D")</title>
      <link>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676523#M204009</link>
      <description>&lt;P&gt;I will merge your meaningless posts here until you start answering to our posts and/or post meaningful questions.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 15:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/syntax-for-if-then-assignment/m-p/676523#M204009</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-13T15:58:40Z</dc:date>
    </item>
  </channel>
</rss>

