<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593412#M170292</link>
    <description>Did not understand your comment sorry. Can you please explain a little more?&lt;BR /&gt;</description>
    <pubDate>Wed, 02 Oct 2019 15:06:32 GMT</pubDate>
    <dc:creator>Dhana18</dc:creator>
    <dc:date>2019-10-02T15:06:32Z</dc:date>
    <item>
      <title>if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593404#M170287</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data uniqueid_count_Provider;
set  uniqueid_count_exclu_other;
if Provider_Name1="PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE" OR Provider_Name1="PLANNED PARENTHOOD-WI AVENUE" OR Provider_Name1="PLANNED PARENTHOOD-NW" 
OR Provider_Name1="BRADY EAST STD CLINIC (BESTD)" OR Provider_Name1="HOLTON ST/*STD SPECIALTIES CLINIC" then Clinic="NSTD";
if Provider_Name1="MILWAUKEE HEALTH DEPARTMENT - KEENAN HEALTH CENTER" OR Provider_Name1="MILWAUKEE HEALTH DEPARTMENT - STD CLINIC" 
OR Provider_Name1="KHC-STD" OR Provider_Name1="KHC-FDTT" then Clinic="STD";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What is wrong with this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log says this:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;158 data uniqueid_count_Provider;&lt;BR /&gt;159 set uniqueid_count_exclu_other;&lt;BR /&gt;160 if Provider_Name1="PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE" OR Provider_Name1="PLANNED&lt;BR /&gt;160! PARENTHOOD-WI AVENUE" OR Provider_Name1="PLANNED PARENTHOOD-NW"&lt;BR /&gt;161 OR Provider_Name1="BRADY EAST STD CLINIC (BESTD)" OR Provider_Name1="HOLTON ST/*STD&lt;BR /&gt;161! SPECIALTIES CLINIC" then Clinic="NSTD";&lt;BR /&gt;162 if Provider_Name1="MILWAUKEE HEALTH DEPARTMENT - KEENAN HEALTH CENTER" OR&lt;BR /&gt;162! Provider_Name1="MILWAUKEE HEALTH DEPARTMENT - STD CLINIC"&lt;BR /&gt;163 OR Provider_Name1="KHC-STD" OR Provider_Name1="KHC-FDTT" then Clinic="STD";&lt;BR /&gt;164 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1416 observations read from the data set WORK.UNIQUEID_COUNT_EXCLU_OTHER.&lt;BR /&gt;NOTE: The data set WORK.UNIQUEID_COUNT_PROVIDER has 1416 observations and 21 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.03 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result is this:(I am not getting the complete records with STD and NSTD categories.)&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Clinic Frequency CumulativeFrequencySTDFrequency Missing = 28 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593404#M170287</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2019-10-02T15:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593408#M170290</link>
      <description>&lt;P&gt;Looks like none of the conditions in your IF statements where true.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593408#M170290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-02T15:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593412#M170292</link>
      <description>Did not understand your comment sorry. Can you please explain a little more?&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593412#M170292</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2019-10-02T15:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593417#M170294</link>
      <description>None of PROVIDER1 values match the values you've typed out. &lt;BR /&gt;Run a PROC FREQ on PROVIDER1 variable and look at the counts and see if you have the values you've listed. Note that it must be an exact match for character variables.</description>
      <pubDate>Wed, 02 Oct 2019 15:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593417#M170294</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-02T15:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593430#M170296</link>
      <description>I actually did proc freq and copied the value into the code.&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593430#M170296</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2019-10-02T15:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593432#M170298</link>
      <description>&lt;P&gt;The first I would do is examine the values that did not get assigned with something like:&lt;/P&gt;
&lt;PRE&gt;data work.junk;
   set uniqueid_count_Provider;
   where missing(clinic);
   keep provider_name1;
run;&lt;/PRE&gt;
&lt;P&gt;Then &lt;STRONG&gt;very&lt;/STRONG&gt; carefully examine those results character by character for something that doesn't match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are using equal comparisons to assign values then any minor change: missing or inserted space, capitalization difference, or extra/missing character will result in missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW I address such items to an extent on my reading data programs with custom informats that tell me when something is different when the external date file is read. And do such assignments with custom formats:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Example:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
invalue $provider (upcase)
"PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE" = "PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE"
"PLANNED PARENTHOOD-WI AVENUE" = "PLANNED PARENTHOOD-WI AVENUE"
"BRADY EAST STD CLINIC (BESTD)" = "BRADY EAST STD CLINIC (BESTD)" 
"KHC-STD" ="KHC-STD"
other= _error_;
value $clinic
"PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE" = "NSTD"
"PLANNED PARENTHOOD-WI AVENUE" = "NSTD"
"BRADY EAST STD CLINIC (BESTD)" = "NSTD" 
"KHC-STD" ="STD"
other="Unknown"
;

data example;
   infile datalines dlm=',';
   informat provider_name1 $provider. ;
   input  provider_name1 somenumber;
datalines;
PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE,1
planned parenthood-express capitol drive,2
PLANNED PARENTHOOD-EXPRESS CAPITOL DRIV,3
PLANNED PARENTHOOD-WI AVENUE,4
pLANNED PARENTHOOD-WI AVENUE,5
BRADY EAST STD CLINIC (BESTD),6
BRADY EAST STD CLINIC,7
Some completely new clinic,8
KHC-STD,9
;
run;

proc freq data=example;
   tables provider_name1;
   format provider_name1 $clinic.;
run;


&lt;/PRE&gt;
&lt;P&gt;Some things to note:&lt;/P&gt;
&lt;P&gt;The INVALUE for Provider will correct capitalization issues. It first converts ANY string to upper case before doing the comparison with the listed values. The target string (on the right of the &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; could be in proper case to make future reading easier, or make a custom display format with the proper case for report writing. The keyword 'other' indicates what to do with any value that does not exactly match the source strings listed. The value _error_ says to treat anything that doesn't match as an error and will write the appropriate invalid data message that any SAS invalid data generates. So when a data source has data entry issues, or as frequently happens with my data, &lt;STRONG&gt;adds&lt;/STRONG&gt; a new provider without telling me, I see the value and can go back to the data source to confirm and collect other information I may need about that provider such as address, billing information, contacts or what have your.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The custom format $Clinic has the logic to do the assignment you started with using your existing variable. There would be very little need for an additional variable for many purposes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has the advantage of when a new clinic is added to the data then I add the value to the format and I do not need to change any code for reports. Also, when you have a variable name like Provider_name1 it makes me suspect there may be a Provider_name2, or 3, or 4. And if they should all becoming from the same list they can share a single informat for data checking when reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For one of my projects I maintain formats for assigning "clinics" to 1)reporting geographical regions 2) reporting types (your STD / NSTD) 3) controlling agencies and have multiple display formats for "short" or "long" provider names. And there are some nice things that can be done with multilabel formats once you get the hang of them. I also have custom informats to check that the values entered for things like insurance, test type, specimen location, test result because things happen when systems are updated or a new reporting entity gets involved and they may take awhile to get things "right".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593432#M170298</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-02T15:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593433#M170299</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212762"&gt;@Dhana18&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I actually did proc freq and copied the value into the code.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Double check you ran PROC FREQ on the same dataset. Also make sure the variable does not have a format attached to it that is causing the values you see in the PROC FREQ to be different than the actual values.&lt;/P&gt;
&lt;P&gt;You could try using the VVALUE() function in your IF statement so you can test based on the formatted values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If vvalue(Provider_Name1) in 
("PLANNED PARENTHOOD-EXPRESS CAPITOL DRIVE" 
,"PLANNED PARENTHOOD-WI AVENUE"
,"PLANNED PARENTHOOD-NW"
,"BRADY EAST STD CLINIC (BESTD)"
,"HOLTON ST/*STD SPECIALTIES CLINIC"
) then Clinic="NSTD";
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593433#M170299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-02T15:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593434#M170300</link>
      <description>&lt;P&gt;What you see in the output of proc freq are formatted values, but in the data step you need to use the raw values, or a put() function with the assigned&amp;nbsp;format.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 15:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-statement/m-p/593434#M170300</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-02T15:34:39Z</dc:date>
    </item>
  </channel>
</rss>

