<?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: IF Statement [how to improve your question] in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442210#M110609</link>
    <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194785"&gt;@Miah&lt;/a&gt;,&lt;/P&gt;&lt;BR /&gt; &lt;P&gt;Your question requires more details before experts can help.&amp;nbsp;Can you revise your question to include more information?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Review this checklist:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Specify a meaningful subject line for your topic.&amp;nbsp; Avoid generic subjects like "need help," "SAS query," or "urgent."&lt;/LI&gt;
&lt;LI&gt;When appropriate, provide sample data in text or DATA step format.&amp;nbsp; See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;this article for one method&lt;/A&gt;&amp;nbsp;you can use.&lt;/LI&gt;
&lt;LI&gt;If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition.&amp;nbsp;Use the&amp;nbsp;&lt;STRONG&gt;Photos&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button to include the image in your message.&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 279px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16608i91A52F817EAC9A69/image-dimensions/279x150?v=1.0" width="279" height="150" alt="use_buttons.png" title="use_buttons.png" /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;It also helps to include an example (table or picture) of the result that you're trying to achieve.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To edit your original message, select the "blue gear" icon at the top of the message and select&amp;nbsp;&lt;STRONG&gt;Edit Message&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;From there you can adjust the title and add more details to the body of the message.&amp;nbsp; Or, simply reply to this message with any additional information you can supply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 229px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16605iAC020BC79315B045/image-size/large?v=1.0&amp;amp;px=600" alt="edit_post.png" title="edit_post.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;SAS experts are eager to help -- help&amp;nbsp;&lt;EM&gt;them&lt;/EM&gt; by providing as much detail as you can.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style:italic;font-size:smaller;"&gt;This prewritten response was triggered for you by fellow SAS Support Communities member &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;.</description>
    <pubDate>Mon, 05 Mar 2018 01:27:28 GMT</pubDate>
    <dc:creator>Community_Guide</dc:creator>
    <dc:date>2018-03-05T01:27:28Z</dc:date>
    <item>
      <title>IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442209#M110608</link>
      <description>&lt;P&gt;I need&amp;nbsp;to create a variable in my data set, indicating how many times each specimen was captured called NumCap. Then I need to alter the AgeGroup variable so that any specimen in the semi-adult group is classi&amp;#12;fied as adult.&lt;/P&gt;&lt;P&gt;Finally I need to print the data set so that only the Sex, AgeGroup, Weight, and NumCap variables are displayed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC IMPORT OUT= work.capture&lt;BR /&gt;	DATAFILE= "/folders/myfolders/Capture.txt"&lt;BR /&gt;	DBMS=CSV REPLACE;&lt;BR /&gt;	DELIMITER='09'x;&lt;BR /&gt;	GETNAMES=YES;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=work.capture;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;DATA capture; &lt;BR /&gt;	SET capture; &lt;BR /&gt;	NumCap = 0;&lt;BR /&gt;	IF (Cap1 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap2 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap3 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap4 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap5 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap6 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA capture; &lt;BR /&gt;	SET capture;&lt;BR /&gt;	IF (AgeGroup == 'semi-adult') THEN DO;&lt;BR /&gt;	AgeGroup = 'Adult';&lt;BR /&gt;RUN;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 01:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442209#M110608</guid>
      <dc:creator>Miah</dc:creator>
      <dc:date>2018-03-05T01:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement [how to improve your question]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442210#M110609</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194785"&gt;@Miah&lt;/a&gt;,&lt;/P&gt;&lt;BR /&gt; &lt;P&gt;Your question requires more details before experts can help.&amp;nbsp;Can you revise your question to include more information?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Review this checklist:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Specify a meaningful subject line for your topic.&amp;nbsp; Avoid generic subjects like "need help," "SAS query," or "urgent."&lt;/LI&gt;
&lt;LI&gt;When appropriate, provide sample data in text or DATA step format.&amp;nbsp; See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;this article for one method&lt;/A&gt;&amp;nbsp;you can use.&lt;/LI&gt;
&lt;LI&gt;If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition.&amp;nbsp;Use the&amp;nbsp;&lt;STRONG&gt;Photos&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button to include the image in your message.&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 279px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16608i91A52F817EAC9A69/image-dimensions/279x150?v=1.0" width="279" height="150" alt="use_buttons.png" title="use_buttons.png" /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;It also helps to include an example (table or picture) of the result that you're trying to achieve.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To edit your original message, select the "blue gear" icon at the top of the message and select&amp;nbsp;&lt;STRONG&gt;Edit Message&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;From there you can adjust the title and add more details to the body of the message.&amp;nbsp; Or, simply reply to this message with any additional information you can supply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 229px;"&gt;&lt;IMG src="https://kntur85557.i.lithium.com/t5/image/serverpage/image-id/16605iAC020BC79315B045/image-size/large?v=1.0&amp;amp;px=600" alt="edit_post.png" title="edit_post.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;SAS experts are eager to help -- help&amp;nbsp;&lt;EM&gt;them&lt;/EM&gt; by providing as much detail as you can.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style:italic;font-size:smaller;"&gt;This prewritten response was triggered for you by fellow SAS Support Communities member &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;.</description>
      <pubDate>Mon, 05 Mar 2018 01:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442210#M110609</guid>
      <dc:creator>Community_Guide</dc:creator>
      <dc:date>2018-03-05T01:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442212#M110610</link>
      <description>&lt;P&gt;What have you tried so far?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Showing what you've attempted makes it easier to help you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're not sure where to start, PROC MEANS calculates summary statistics and PROC FREQ generates summary counts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This section has a lot of tutorials and the first two programming e-courses are free.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://video.sas.com/#category/videos/sas-analytics-u" target="_blank"&gt;http://video.sas.com/#category/videos/sas-analytics-u&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 01:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442212#M110610</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-05T01:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442214#M110611</link>
      <description>&lt;PRE&gt;PROC IMPORT OUT= work.capture&lt;BR /&gt;	DATAFILE= "/folders/myfolders/Capture.txt"&lt;BR /&gt;	DBMS=CSV REPLACE;&lt;BR /&gt;	DELIMITER='09'x;&lt;BR /&gt;	GETNAMES=YES;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=work.capture;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;DATA capture; &lt;BR /&gt;	SET capture; &lt;BR /&gt;	NumCap = 0;&lt;BR /&gt;	IF (Cap1 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap2 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap3 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap4 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap5 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;	IF (Cap6 == 'yes') THEN DO; &lt;BR /&gt;	NumCap +1; &lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;DATA capture; &lt;BR /&gt;	SET capture;&lt;BR /&gt;	IF (AgeGroup == 'semi-adult') THEN DO;&lt;BR /&gt;	AgeGroup = 'Adult';&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 01:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442214#M110611</guid>
      <dc:creator>Miah</dc:creator>
      <dc:date>2018-03-05T01:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442226#M110615</link>
      <description>&lt;PRE&gt;DATA capture; &lt;BR /&gt;	SET capture; &lt;/PRE&gt;
&lt;P&gt;Coding like that makes it really hard to figure out where you made a mistake, make sure each DATA creates a unique data set instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;SAS does not use a double == to test equality, a single equal sign is necessary. How does this code not work or meet your expectations? What are you expecting as output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have an THEN DO block, &amp;nbsp;it needs an END.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	IF (AgeGroup == 'semi-adult') THEN DO;
	AgeGroup = 'Adult';
        END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 02:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442226#M110615</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-05T02:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442228#M110617</link>
      <description>&lt;P&gt;A few changes to the basic syntax will do the trick.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, if you want to do something, just do it.&amp;nbsp; You don't have to say THEN DO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, you only need one equal sign to assign a value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set capture;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;NumCap = 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap1='yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap2='yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap3='yes' then Numcap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap4='yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap5='yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if Cap6='yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if AgeGroup = 'semi-adult' then AgeGroup = 'Adult';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are ways to shorten the amount of code, using an array to hold Cap1 through Cap6.&amp;nbsp; I omitted that intentionally, since it is more complex and you are still working on some more basic statements.&amp;nbsp; Just in case it proves useful, these statements could replace 6 IF/THEN statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array cap {6};&lt;/P&gt;
&lt;P&gt;do k=1 to 6;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if cap{k} = 'yes' then NumCap + 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop k;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 02:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442228#M110617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-05T02:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442229#M110618</link>
      <description>&lt;P&gt;Pay attention to sas syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) &lt;STRONG&gt;DO;&lt;/STRONG&gt; statement is used to do one or more statements, each ending by a semicolon (;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; You have to enclose the &lt;STRONG&gt;DO;&lt;/STRONG&gt; by &lt;STRONG&gt;END;&lt;/STRONG&gt; statement as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do;
     &amp;lt;statement 1&amp;gt;;
     &amp;lt;statement 2&amp;gt;;
     ....
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) When you have just one statement to do you don't need a DO; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; You can use a more simple syntax like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;lt;condition&amp;gt; then &amp;lt;statement&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) You can eclose the two missions into one data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) Using above syntax, makes your code into:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA capture; 
	SET capture; 
	NumCap = 0;
	IF Cap1 = 'yes'  THEN NumCap +1; 
	IF Cap2 = 'yes'  THEN NumCap +1; 
	IF Cap3 = 'yes'  THEN NumCap +1; 
	IF Cap4 = 'yes'  THEN NumCap +1; 
	IF Cap5 = 'yes'  THEN NumCap +1; 
	IF Cap6 = 'yes'  THEN NumCap +1; 

       IF Agegroup = 'semi-adult' then Agegroup = 'Adult';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;5) Next code is eqivalent to the above:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA capture; 
	SET capture; 
	NumCap = 0;
        array cp Cap1-Cap5;
        do i=1 to 5;
            if cp(i) = 'yes' then numcap +1;
        end;

	IF agegroup = 'semi-adult' then agegroup = 'adult';
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 02:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statement/m-p/442229#M110618</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-03-05T02:34:56Z</dc:date>
    </item>
  </channel>
</rss>

