<?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-THEN Statement Only Work For the First Row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927906#M365112</link>
    <description>Hi Cynthia, thanks for your reply! This is just an exercise from SAS Base Prep.</description>
    <pubDate>Fri, 10 May 2024 17:41:28 GMT</pubDate>
    <dc:creator>judyzhang1991</dc:creator>
    <dc:date>2024-05-10T17:41:28Z</dc:date>
    <item>
      <title>IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927849#M365089</link>
      <description>&lt;P&gt;Hi, I am new to SAS and I am trying to input data from the a .txt file. Could someone please help me figure out why the IF-THEN statement only applies to the first row of the data? Thanks!&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-10 at 9.28.46 AM.png" style="width: 624px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96408iB9B37CBC283B41BA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-05-10 at 9.28.46 AM.png" alt="Screenshot 2024-05-10 at 9.28.46 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA work.condo_ranch;
	INFILE '/home/u63748921/SAS 123 Problems/sas123_p13.txt' DSD;
	INPUT style $ @;
	IF style = 'RANCH' OR style = 'CONDO' THEN INPUT sqfeet bedrooms baths street $ price : dollar10.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-10 at 9.38.59 AM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96407i36D15929869271A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-05-10 at 9.38.59 AM.png" alt="Screenshot 2024-05-10 at 9.38.59 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 14:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927849#M365089</guid>
      <dc:creator>judyzhang1991</dc:creator>
      <dc:date>2024-05-10T14:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927853#M365093</link>
      <description>&lt;P&gt;What does your LOG for running that data step look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can't test code against pictures of data. Can you copy the TEXT of the file and then paste that into a text box opened on the forum using the &amp;lt;/&amp;gt; icon that appears above the message window?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest adding DLM=',' to the infile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: you may want to define the length of STYLE variable to be longer than the default 8 characters that results from using Input Style $ . The picture you show with TWOSTOR appearing as the style might be an indicator that something a bit odd is going on. Your STREET variable definitely needs a longer length to hold the values shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA work.condo_ranch;
	INFILE '/home/u63748921/SAS 123 Problems/sas123_p13.txt' DSD Dlm=',';
	INPUT style : $10. @;
	IF style = 'RANCH' OR style = 'CONDO' THEN INPUT sqfeet bedrooms baths street : $20. price : dollar10.;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 May 2024 15:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927853#M365093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-10T15:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927872#M365102</link>
      <description>&lt;P&gt;Hi Ballardw, thanks for replying to my post. This is my first time posting here and I am sorry if I messed up with the format. The text is here:&lt;/P&gt;&lt;PRE&gt;RANCH,1250,2,1,Sheppard Avenue,"64,000"
SPLIT,1190,1,1,Rand Street,"$65,850"
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY,1810,4,3,Garris Street,"$107.250"
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT,1615,4,3,West Drive,"94,450"
SPLIT,1305,3,1.5,Graham Avenue,"$73,650"&lt;/PRE&gt;&lt;P&gt;Here is my log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         DATA work.condo_ranch;
 70         INFILE '/home/u63748921/SAS 123 Problems/sas123_p13.txt' DSD DLM=',';
 71         INPUT style : $10. @;
 72         IF style = 'RANCH' OR style = 'CONDO' THEN INPUT sqfeet bedrooms baths street : $20. price : dollar10.;
 73         RUN;
 
 NOTE: The infile '/home/u63748921/SAS 123 Problems/sas123_p13.txt' is:
       Filename=/home/u63748921/SAS 123 Problems/sas123_p13.txt,
       Owner Name=u63748921,Group Name=oda,
       Access Permission=-rw-r--r--,
       Last Modified=09May2024:09:49:58,
       File Size (bytes)=282
 
 NOTE: 8 records were read from the infile '/home/u63748921/SAS 123 Problems/sas123_p13.txt'.
       The minimum record length was 1.
       The maximum record length was 43.
 NOTE: The data set WORK.CONDO_RANCH has 8 observations and 6 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              797.00k
       OS Memory           19620.00k
       Timestamp           05/10/2024 04:00:32 PM
       Step Count                        24  Switch Count  2
       Page Faults                       0
       Page Reclaims                     207
       Page Swaps                        0
       Voluntary Context Switches        21
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264
       
 
 74         
 75         
 76         
 77         
 78         
 79         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 89         
 User: u63748921&lt;/PRE&gt;&lt;P&gt;Thanks for the suggestions about defining the length of variables. I have made those changes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 16:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927872#M365102</guid>
      <dc:creator>judyzhang1991</dc:creator>
      <dc:date>2024-05-10T16:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927878#M365103</link>
      <description>&lt;P&gt;When I run this code with the data in-line:&lt;/P&gt;
&lt;PRE&gt;DATA work.condo_ranch;
 INFILE datalines DSD DLM=',';
 INPUT style : $10. @;
 IF style = 'RANCH' OR style = 'CONDO' THEN INPUT sqfeet bedrooms baths street : $20. price : dollar10.;
datalines;
RANCH,1250,2,1,Sheppard Avenue,"64,000"
SPLIT,1190,1,1,Rand Street,"$65,850"
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY,1810,4,3,Garris Street,"$107.250"
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT,1615,4,3,West Drive,"94,450"
SPLIT,1305,3,1.5,Graham Avenue,"$73,650"
;
 RUN;&lt;/PRE&gt;
&lt;P&gt;I get this result:&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;A name="IDX8" target="_blank"&gt;&lt;/A&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.CONDO_RANCH" cellspacing="0" cellpadding="3"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c m header" scope="col"&gt;style&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;sqfeet&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;bedrooms&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;baths&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;street&lt;/TH&gt;
&lt;TH class="c m header" scope="col"&gt;price&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;RANCH&lt;/TD&gt;
&lt;TD class="r data"&gt;1250&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1.0&lt;/TD&gt;
&lt;TD class="l data"&gt;Sheppard Avenue&lt;/TD&gt;
&lt;TD class="r data"&gt;64000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;SPLIT&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;CONDO&lt;/TD&gt;
&lt;TD class="r data"&gt;1400&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1.5&lt;/TD&gt;
&lt;TD class="l data"&gt;Market Street&lt;/TD&gt;
&lt;TD class="r data"&gt;80050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;TWOSTORY&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;RANCH&lt;/TD&gt;
&lt;TD class="r data"&gt;1500&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;3.0&lt;/TD&gt;
&lt;TD class="l data"&gt;Kemble Avenue&lt;/TD&gt;
&lt;TD class="r data"&gt;86650&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;SPLIT&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;SPLIT&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't match the output reading your file then you may need to look at your file for something odd buried in the data.&lt;/P&gt;
&lt;P&gt;I suspect that your file has a blank line at the bottom which is why your log shows 8 observations in the data for 7 lines of actual text in the file.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 10 May 2024 16:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927878#M365103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-10T16:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927902#M365109</link>
      <description>&lt;P&gt;Hi Ballardw, thanks again for help! It is indeed something wrong with the .txt file. I recreated and it solved the problem.&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 17:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927902#M365109</guid>
      <dc:creator>judyzhang1991</dc:creator>
      <dc:date>2024-05-10T17:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927904#M365111</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;The bigger question for me is whether you want only output the rows where STYLE is RANCH or CONDO. Right now, you're reading every row, but only catching the other variables for the RANCH or CONDO rows. I don't see the point of outputting the basically empty rows for the other STYLE types.&lt;BR /&gt;Cynthia&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
 DATA work.condo_ranch;
 INFILE datalines DSD DLM=',';
 INPUT style : $10. @;
 ** use subsetting if to limit output rows;
 if style in ('RANCH' ,'CONDO'); 
 INPUT sqfeet bedrooms baths street : $20. price : dollar10.;
datalines;
RANCH,1250,2,1,Sheppard Avenue,"64,000"
SPLIT,1190,1,1,Rand Street,"$65,850"
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY,1810,4,3,Garris Street,"$107,250"
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT,1615,4,3,West Drive,"94,450"
SPLIT,1305,3,1.5,Graham Avenue,"$73,650"
;
RUN;

title 'condo_ranch made with subsetting IF';
proc print data=work.condo_ranch;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produces this output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1715362745770.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96417iD8F3360B9683AC48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1715362745770.png" alt="Cynthia_sas_0-1715362745770.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 17:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927904#M365111</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-05-10T17:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927906#M365112</link>
      <description>Hi Cynthia, thanks for your reply! This is just an exercise from SAS Base Prep.</description>
      <pubDate>Fri, 10 May 2024 17:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927906#M365112</guid>
      <dc:creator>judyzhang1991</dc:creator>
      <dc:date>2024-05-10T17:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927911#M365114</link>
      <description>Hi:&lt;BR /&gt;  Thanks for letting me know. I like to post alternate code like this for completeness, in case somebody looks at the solution and wonders how they would only get the "filled-in" rows just by modifying the original program.&lt;BR /&gt;Cynthia&lt;BR /&gt;</description>
      <pubDate>Fri, 10 May 2024 17:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927911#M365114</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-05-10T17:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN Statement Only Work For the First Row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927930#M365117</link>
      <description>That is very helpful! Thanks!</description>
      <pubDate>Fri, 10 May 2024 19:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Statement-Only-Work-For-the-First-Row/m-p/927930#M365117</guid>
      <dc:creator>judyzhang1991</dc:creator>
      <dc:date>2024-05-10T19:10:44Z</dc:date>
    </item>
  </channel>
</rss>

